ramtinak / InstagramApiSharp

A complete Private Instagram API for .NET (C#, VB.NET).
MIT License
792 stars 239 forks source link

Object null ref within newton json when attempting to get a highlight feed #208

Closed NateKomodo closed 5 years ago

NateKomodo commented 5 years ago

I've:

Issue category

Language

Usage

Operating System

Debug logs

Exception: System.NullReferenceException: Object reference not set to an instance of an object. at InstagramApiSharp.Converters.Json.InstaHighlightReelsListDataConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonConverter[] converters) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters) at InstagramApiSharp.API.Processors.StoryProcessor.<GetHighlightsArchiveMediasAsync>d__16.MoveNext() Stacktrace: at InstagramApiSharp.Converters.Json.InstaHighlightReelsListDataConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonConverter[] converters) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters) at InstagramApiSharp.API.Processors.StoryProcessor.<GetHighlightsArchiveMediasAsync>d__16.MoveNext()

Describe your issue

Object null ref within newton json when attempting to get a highlight feed var mediareq = await API.api.StoryProcessor.GetHighlightsArchiveMediasAsync(storyID); No matter the format the ID is passed in, it will always cause the above error (e.g. "highlight:00123456789012345" or "00123456789012345")

EDIT: Formatting

ramtinak commented 5 years ago

Note that GetHighlightsArchiveMediasAsync is for your OWN highlighted stories archive.

It's OK for me:

var archivedHighlights = await InstaApi.StoryProcessor.GetHighlightsArchiveAsync();
var first = archivedHighlights.Value.Items.FirstOrDefault();

var archiveHighlightMedias = await InstaApi.StoryProcessor.GetHighlightsArchiveMediasAsync(first.Id);

Results: image

As you can see everything is OK and works fine.

Logs:

3/9/2019 6:04:18 PM:    ----------------------------------------------------------------------------------------------------
3/9/2019 6:04:18 PM:    Request: GET https://i.instagram.com/api/v1/archive/reel/day_shells/?include_cover=0
3/9/2019 6:04:18 PM:    Headers:
3/9/2019 6:04:19 PM:    Accept-Language:["en-US"]
3/9/2019 6:04:19 PM:    X-IG-Capabilities:["3brTvw=="]
3/9/2019 6:04:19 PM:    X-IG-Connection-Type:["WIFI"]
3/9/2019 6:04:19 PM:    User-Agent:["Instagram","76.0.0.15.395","Android","(27/8.1; 640dpi; 1440x2560; LGE; hammerhead; hammerhead; Nexus 5; en_US; 138226743)"]
3/9/2019 6:04:19 PM:    X-IG-App-ID:["567067343352427"]
3/9/2019 6:04:21 PM:    Response: GET https://i.instagram.com/api/v1/archive/reel/day_shells/?include_cover=0 [OK]
3/9/2019 6:04:21 PM:    Content:
3/9/2019 6:04:21 PM:    {"items": [{"timestamp": 1552089700, "media_count": 2, "id": "archiveDay:17875140562318051", "reel_type": "archive_day_reel", "latest_reel_media": 1552141200}, {"timestamp": 1551744100, "media_count": 3, "id": "archiveDay:18009438541146143", "reel_type": "archive_day_reel", "latest_reel_media": 1551809282}, {"timestamp": 1548633700, "media_count": 1, "id": "archiveDay:18027268369048374", "reel_type": "archive_day_reel", "latest_reel_media": 1548621533}], "num_results": 3, "more_available": false, "max_id": null, "status": "ok"}
3/9/2019 6:04:22 PM:    ----------------------------------------------------------------------------------------------------
3/9/2019 6:04:22 PM:    Request: POST https://i.instagram.com/api/v1/feed/reels_media/
3/9/2019 6:04:22 PM:    Headers:
3/9/2019 6:04:22 PM:    Accept-Language:["en-US"]
3/9/2019 6:04:22 PM:    X-IG-Capabilities:["3brTvw=="]
3/9/2019 6:04:22 PM:    X-IG-Connection-Type:["WIFI"]
3/9/2019 6:04:22 PM:    User-Agent:["Instagram","76.0.0.15.395","Android","(27/8.1; 640dpi; 1440x2560; LGE; hammerhead; hammerhead; Nexus 5; en_US; 138226743)"]
3/9/2019 6:04:22 PM:    X-IG-App-ID:["567067343352427"]
3/9/2019 6:04:22 PM:    Properties:
{
  "signed_body": "57bdc963ad24de44c948eb3f3c3947bc11270061a1e5ed725f23c1c5dd85f95b.{\"supported_capabilities_new\":\"[{\\\"name\\\":\\\"SUPPORTED_SDK_VERSIONS\\\",\\\"value\\\":\\\"13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,37.0,38.0,39.0,40.0,41.0,42.0,43.0,44.0,45.0,46.0,47.0,48.0,49.0,50.0,51.0,52.0,53.0\\\"},{\\\"name\\\":\\\"FACE_TRACKER_VERSION\\\",\\\"value\\\":\\\"12\\\"},{\\\"name\\\":\\\"segmentation\\\",\\\"value\\\":\\\"segmentation_enabled\\\"},{\\\"name\\\":\\\"COMPRESSION\\\",\\\"value\\\":\\\"ETC2_COMPRESSION\\\"},{\\\"name\\\":\\\"WORLD_TRACKER\\\",\\\"value\\\":\\\"WORLD_TRACKER_ENABLED\\\"}]\",\"source\":\"reel_highlights_gallery\",\"_csrftoken\":\"XS8sqTcMVn49F6wVbwqf1r7Y5s1xWHbw\",\"_uid\":\"5318277344\",\"_uuid\":\"80d37821-3eeb-46e9-ad44-39f3f9b9fac5\",\"user_ids\":[\"archiveDay:17875140562318051\"]}",
  "ig_sig_key_version": "4"
}
3/9/2019 6:04:22 PM:    Content:
3/9/2019 6:04:22 PM:    signed_body=dsfgfrhyrtrthfrghcg345tergtsdrgsafdnjgkhi67i6ti6tigtjt.{"supported_capabilities_new":"[{\"name\":\"SUPPORTED_SDK_VERSIONS\",\"value\":\"13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,37.0,38.0,39.0,40.0,41.0,42.0,43.0,44.0,45.0,46.0,47.0,48.0,49.0,50.0,51.0,52.0,53.0\"},{\"name\":\"FACE_TRACKER_VERSION\",\"value\":\"12\"},{\"name\":\"segmentation\",\"value\":\"segmentation_enabled\"},{\"name\":\"COMPRESSION\",\"value\":\"ETC2_COMPRESSION\"},{\"name\":\"WORLD_TRACKER\",\"value\":\"WORLD_TRACKER_ENABLED\"}]","source":"reel_highlights_gallery","_csrftoken":"XS8sqTcMVn49F6wVbwqf1r7Y5s1xWHbw","_uid":"5318277344","_uuid":"80d37821-3eeb-46e9-ad44-39f3f9b9fac5","user_ids":["archiveDay:17875140562318051"]}&ig_sig_key_version=4
3/9/2019 6:04:22 PM:    Response: POST https://i.instagram.com/api/v1/feed/reels_media/ [OK]
3/9/2019 6:04:22 PM:    Content:
3/9/2019 6:04:22 PM:    {"reels": {"archiveDay:17875140562318051": {"id": "archiveDay:17875140562318051", "latest_reel_media": 1552141200, "seen": null, "can_reply": false, "can_reshare": true, "reel_type": "archive_day_reel", "cover_media": {"cropped_image_version": {"width": 150, "height": 150, "url": "https://scontent-frt3-2.cdninstagram.com/vp/7a20eb2125f977b94f3bfe2a5abf7b5b/5C85FF4E/t51.12442-15/e35/c0.357.1080.1080/s150x150/53117313_2224016397620483_4976637063504884385_n.jpg?_nc_ht=scontent-frt3-2.cdninstagram.com"}, "crop_rect": null, "media_id": "1995827369616918505_5318277344"}, "user": {"pk": 5318277344, "username": "rmt4006", "full_name": "Rmt", "is_private": false, "profile_pic_url": "https://scontent-arn2-2.cdninstagram.com/vp/1012e57294e06bf834485c8fc9ece5c5/5D0566F1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-arn2-2.cdninstagram.com", "is_verified": false}, "items": [{"taken_at": 1552141179, "pk": 1995827369616918505, "id": "1995827369616918505_5318277344", "device_timestamp": 8249748781552, "media_type": 1, "code": "BuymmsXBMfp", "client_cache_key": "MTk5NTgyNzM2OTYxNjkxODUwNQ==.2", "filter_type": 0, "image_versions2": {"candidates": [{"width": 1080, "height": 1794, "url": "https://scontent-frt3-2.cdninstagram.com/vp/bb2a769a4d5573592f32122deb74d2ce/5C866C0F/t51.12442-15/e35/53117313_2224016397620483_4976637063504884385_n.jpg?_nc_ht=scontent-frt3-2.cdninstagram.com\u0026se=7\u0026ig_cache_key=MTk5NTgyNzM2OTYxNjkxODUwNQ%3D%3D.2"}, {"width": 240, "height": 398, "url": "https://scontent-frt3-2.cdninstagram.com/vp/3eb53923608ecd9be7355ea091e58309/5C86EA06/t51.12442-15/e35/p240x240/53117313_2224016397620483_4976637063504884385_n.jpg?_nc_ht=scontent-frt3-2.cdninstagram.com\u0026ig_cache_key=MTk5NTgyNzM2OTYxNjkxODUwNQ%3D%3D.2"}]}, "original_width": 1080, "original_height": 1794, "caption_position": 0.0, "is_reel_media": true, "timezone_offset": 12600, "user": {"pk": 5318277344, "username": "rmt4006", "full_name": "Rmt", "is_private": false, "profile_pic_url": "https://scontent-arn2-2.cdninstagram.com/vp/1012e57294e06bf834485c8fc9ece5c5/5D0566F1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-arn2-2.cdninstagram.com", "is_verified": false, "has_anonymous_profile_picture": true, "can_boost_post": false, "can_see_organic_insights": false, "show_insights_terms": false, "reel_auto_archive": "on", "is_unpublished": false, "allowed_commenter_type": "any"}, "caption": null, "caption_is_edited": false, "photo_of_you": false, "fb_user_tags": {"in": []}, "can_viewer_save": true, "organic_tracking_token": "eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjM3YTIyYzNkZTNiNTQwOTFhYWJiOWVlZWZiYTg1ZTUzMTk5NTgyNzM2OTYxNjkxODUwNSIsInNlcnZlcl90b2tlbiI6IjE1NTIxNDIwNjI2NDd8MTk5NTgyNzM2OTYxNjkxODUwNXw1MzE4Mjc3MzQ0fDMxYjVhMjkxZTUwNzE4NzU4ODQxNmViNDcxMDU2MDhkNWY3ZDFlMjQxYWNkOTQ1MGVjYjcyNDNiNzNlOWUyMzgifSwic2lnbmF0dXJlIjoiIn0=", "can_reshare": true, "can_reply": false, "story_is_saved_to_archive": true, "highlight_reel_ids": ["highlight:17949376975252307"], "viewers": [{"pk": 2097318492, "username": "hseyinn", "full_name": "H\u00fcseyin", "is_private": true, "profile_pic_url": "https://scontent-frt3-2.cdninstagram.com/vp/a4afc6c58be763f35482cff2c5b1151e/5D05C294/t51.2885-19/s150x150/45351112_2105752626102258_2318950794134552576_n.jpg?_nc_ht=scontent-frt3-2.cdninstagram.com", "profile_pic_id": "1913122986242465903_2097318492", "is_verified": false}], "viewer_count": 1, "viewer_cursor": null, "total_viewer_count": 1, "multi_author_reel_names": [], "supports_reel_reactions": true, "show_one_tap_fb_share_tooltip": true, "has_shared_to_fb": 0}, {"taken_at": 1552141200, "pk": 1995827543127073461, "id": "1995827543127073461_5318277344", "device_timestamp": 8270905868007, "media_type": 1, "code": "BuympN9B6K1", "client_cache_key": "MTk5NTgyNzU0MzEyNzA3MzQ2MQ==.2", "filter_type": 0, "image_versions2": {"candidates": [{"width": 1080, "height": 1794, "url": "https://scontent-frt3-2.cdninstagram.com/vp/0ba35021d54e0345f128ed168c6ee403/5C86DEFF/t51.12442-15/e35/52486752_1200121176819638_3528247351810377000_n.jpg?_nc_ht=scontent-frt3-2.cdninstagram.com\u0026se=7\u0026ig_cache_key=MTk5NTgyNzU0MzEyNzA3MzQ2MQ%3D%3D.2"}, {"width": 240, "height": 398, "url": "https://scontent-frt3-2.cdninstagram.com/vp/e1d609a4cb801c059b9e064fcefc5a36/5C861476/t51.12442-15/e35/p240x240/52486752_1200121176819638_3528247351810377000_n.jpg?_nc_ht=scontent-frt3-2.cdninstagram.com\u0026ig_cache_key=MTk5NTgyNzU0MzEyNzA3MzQ2MQ%3D%3D.2"}]}, "original_width": 1080, "original_height": 1794, "caption_position": 0.0, "is_reel_media": true, "timezone_offset": 12600, "user": {"pk": 5318277344, "username": "rmt4006", "full_name": "Rmt", "is_private": false, "profile_pic_url": "https://scontent-arn2-2.cdninstagram.com/vp/1012e57294e06bf834485c8fc9ece5c5/5D0566F1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-arn2-2.cdninstagram.com", "is_verified": false, "has_anonymous_profile_picture": true, "can_boost_post": false, "can_see_organic_insights": false, "show_insights_terms": false, "reel_auto_archive": "on", "is_unpublished": false, "allowed_commenter_type": "any"}, "caption": null, "caption_is_edited": false, "photo_of_you": false, "fb_user_tags": {"in": []}, "can_viewer_save": true, "organic_tracking_token": "eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjM3YTIyYzNkZTNiNTQwOTFhYWJiOWVlZWZiYTg1ZTUzMTk5NTgyNzU0MzEyNzA3MzQ2MSIsInNlcnZlcl90b2tlbiI6IjE1NTIxNDIwNjI2NDh8MTk5NTgyNzU0MzEyNzA3MzQ2MXw1MzE4Mjc3MzQ0fDhiMzU2YjA2OWMxOWZhYjBlMjQyMTZmOWE2NzRhMGEzNjVlYjk5YzU5M2ExMjM2OWRmNDBmZmRhZDRmZDU0YzkifSwic2lnbmF0dXJlIjoiIn0=", "can_reshare": true, "can_reply": false, "story_is_saved_to_archive": true, "highlight_reel_ids": ["highlight:17949376975252307"], "viewers": [{"pk": 2097318492, "username": "hseyinn", "full_name": "H\u00fcseyin", "is_private": true, "profile_pic_url": "https://scontent-frt3-2.cdninstagram.com/vp/a4afc6c58be763f35482cff2c5b1151e/5D05C294/t51.2885-19/s150x150/45351112_2105752626102258_2318950794134552576_n.jpg?_nc_ht=scontent-frt3-2.cdninstagram.com", "profile_pic_id": "1913122986242465903_2097318492", "is_verified": false}], "viewer_count": 1, "viewer_cursor": null, "total_viewer_count": 1, "multi_author_reel_names": [], "supports_reel_reactions": true, "show_one_tap_fb_share_tooltip": true, "has_shared_to_fb": 0}], "title": "", "created_at": 1552089700, "prefetch_count": 0, "media_count": 2, "contains_stitched_media_blocked_by_rm": false}}, "status": "ok"}
NateKomodo commented 5 years ago

Ah, how am i supposed to get stories or highlights for other users then? (From IDs)

ramtinak commented 5 years ago
var user = await InstaApi.UserProcessor.GetUserAsync("desire username");
var userId = user.Value.Pk;

// all highlights categories
// this is for getting Cover picture and Title from highlights categories
var highlights = await InstaApi.StoryProcessor.GetHighlightFeedsAsync(userId);

// highlight medias for single hightlight category
var single = highlights.Value.Items.FirstOrDefault();

var hlMedias = await InstaApi.StoryProcessor.GetHighlightMediasAsync(single.HighlightId);

Good luck.

NateKomodo commented 5 years ago

That is the exact code i have and it does not work await API.api.StoryProcessor.GetHighlightMediasAsync(storyID); and got the ID from: await API.api.StoryProcessor.GetHighlightFeedsAsync(user.Result.Value.Pk).Value.Items.FirstOrDefault().HighlightId;

ramtinak commented 5 years ago

Note that Highlight is an archived story but you can't use storyId in GetHighlightMediasAsync. you must use highlight id.

If you want to get stories from specific user, use GetUserStoryFeedAsync(userid). Also you must check for Succeeded property. for example:

var highlights = await InstaApi.StoryProcessor.GetHighlightFeedsAsync(userId);
if(highlights.Succeeded)
{
 // OK response
}
else
{
 // wrong response, error, exception and others
}

You also must check for Items null checks too. You can't use .GetHighlightFeedsAsync(user.Result.Value.Pk).Value.Items.FirstOrDefault().HighlightId directly! as I said before, you must checks for Succeeded first... Please check all examples projects and search for story in issues.

Good luck.

NateKomodo commented 5 years ago

Getting the IDs isnt the problem and is working fine, as i have said previously its just GetHighlightMediasAsync with a valid highlight ID that is throwing the error

ramtinak commented 5 years ago

So it appears there was a bug in highlight converter, this when appeared that I was using your highlight id ( highlight:00123456789012345).

I think this highlight belongs to a private user or maybe it's removed. that's why we got this response:

3/10/2019 9:25:06 PM:   Response: POST https://i.instagram.com/api/v1/feed/reels_media/ [OK]
3/10/2019 9:25:06 PM:   Content:
3/10/2019 9:25:06 PM:   {"reels": {}, "status": "ok"}
NateKomodo commented 5 years ago

Oh no, that was just an example of the highlight id format

ramtinak commented 5 years ago

so give me a correct highlight id that you are giving exception.

NateKomodo commented 5 years ago

highlight:18032175832051650 valid, but account is private, i am following the person.

ramtinak commented 5 years ago

Do one of these:

  1. post your debug log (not exception, only debug logs) here. It will appears in Visual Studio Output Window if you enable debug logs: https://github.com/ramtinak/InstagramApiSharp/blob/484ca57f14e8435a16eb7992df44155e1749c20d/samples/ChallengeRequireExample/Form1.cs#L112 image

  2. Give me the username you are testing, I'm gonna follow him/her to test this.

NateKomodo commented 5 years ago

Ah figured it out, was deserializing the wrong data and passing in an actual media ID instead of highlight ID (Result of a bad copy-paste), all good now