instagram-web-api icon indicating copy to clipboard operation
instagram-web-api copied to clipboard

Cannot read property 'shortcode_media' of undefined

Open WilliamTraoreee opened this issue 4 years ago • 8 comments

Hello

I have a problem with "getMediaByShortcode" endpoint, I have the error :

TypeError: Cannot read property 'shortcode_media' of undefined

Thanks a lot for the help

WilliamTraoreee avatar Jun 17 '21 23:06 WilliamTraoreee

Hey, could you share your entire code please ? Thanks.

MonsieurBibo avatar Jun 18 '21 13:06 MonsieurBibo

I also had the same problem this morning suddenly. The app was working perfectly fine up to 12 hours ago.

Example Post URL: https://www.instagram.com/p/CHAIm2sHSQZ/

I injected a console log into the getMediaByShortcode method in index.js

{ items:
   [ { taken_at: 1604134864,
       pk: 2431981653214438400,
       id: '2431981653214438425_42241297565',
       device_timestamp: 391120207524693,
       media_type: 2,
       code: 'CHAIm2sHSQZ',
       client_cache_key: 'MjQzMTk4MTY1MzIxNDQzODQyNQ==.2',
       filter_type: 0,
       is_unified_video: false,
       user: [Object],
       can_viewer_reshare: true,
       caption_is_edited: false,
       like_and_view_counts_disabled: false,
       liker_config: [Object],
       featured_products_cta: null,
       is_commercial: true,
       commerciality_status: 'not_commercial',
       is_paid_partnership: false,
       playlist_eligibility: true,
       comments_disabled: true,
       title: 'What happens next is up to us',
       product_type: 'igtv',
       nearly_complete_copyright_match: false,
       media_cropping_info: [Object],
       thumbnails: [Object],
       igtv_exists_in_viewer_series: false,
       is_post_live: false,
       image_versions2: [Object],
       original_width: 540,
       original_height: 840,
       like_count: 251107,
       has_liked: false,
       top_likers: [Array],
       facepile_top_likers: [Array],
       photo_of_you: false,
       can_see_insights_as_brand: false,
       is_dash_eligible: 1,
       video_dash_manifest: //omitted for brevity,
       video_codec: 'avc1.64001F',
       number_of_qualities: 4,
       video_versions: [Array],
       has_audio: true,
       video_duration: 86.633,
       view_count: 1496727,
       caption: [Object],
       can_viewer_save: true,
       organic_tracking_token:
        'eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjp0cnVlLCJ1dWlkIjoiMDJjN2MxY2RlNTRjNDk4ZGI5MzQ0MDYzYmU3NzM4Y2EyNDMxOTgxNjUzMjE0NDM4NDI1Iiwic2VydmVyX3Rva2VuIjoiMTYzNTAyMjMzNTM0NXwyNDMxOTgxNjUzMjE0NDM4NDI1fDQ1MDkwNDk1MTIzfGM4YjA4MmQ4NTc1MDA4YzRhNjk4ZWUwYWQzYjRmODVhNDI3YTU4MTM5N2IzMTQ4YmIyY2FjMTk5YmNmNTI2ODYifSwic2lnbmF0dXJlIjoiIn0=',
       sharing_friction_info: [Object],
       is_in_profile_grid: false,
       profile_grid_control_enabled: false,
       deleted_reason: 0,
       integrity_review_decision: 'approved',
       music_metadata: [Object] } ],
  num_results: 1,
  more_available: false,
  auto_load_more_enabled: false }

Not sure if this is a permanent change, but at least the original data structure is different now... data.graphql.shortcode_media does not seem to exist.

the weird thing is if i go to https://www.instagram.com/p/CHAIm2sHSQZ/?__a=1

{"graphql":{"shortcode_media":{"__typename":"GraphVideo","id":"2431981653214438425","shortcode":"CHAIm2sHSQZ","dimensions":{"height":995,"width":640},"gating_info":null,"fact_check_overall_rating":null,"fact_check_information":null,"sensitivity_friction_info":null,"sharing_friction_info":

...

then graphQL key is present, so im not sure why there is a discrepency

ronaldho avatar Oct 23 '21 21:10 ronaldho

Okay, I did a bit more digging, one of my accounts returns the top result under items, but if i view the same post URL with the ?__a=1, then it returns the graphql format

ronaldho avatar Oct 23 '21 21:10 ronaldho

if i try to match the params from the new items array to match the previous params from getMediaShortcode, and then try to like or submit a comment, I get this response

Name: StatusCodeError StatusCode 400 message: 400 - "Sorry, this photo has been deleted" Error: "Sorry, this photo has been deleted" URI: /web/likes/{id}/like/ Form: undefined

but i know for a fact that its not deleted

ronaldho avatar Oct 23 '21 21:10 ronaldho

Okay, It was my mistake earlier, I thought the new "PK" key and the ID key is the same, but actually it is not, so i used a regex to lop off the numbers after the underscore.

After that I did some other mapping in my code to account for the place where data moved around

But hopefully this is a temporary change and not a shift to where the getMediaByShortcode is going towards

ronaldho avatar Oct 23 '21 22:10 ronaldho

same problem here

PedroBatistop avatar Nov 14 '21 18:11 PedroBatistop

same problem here too.

eileenhlee avatar Mar 24 '22 19:03 eileenhlee

Okay, I did a bit more digging, one of my accounts returns the top result under items, but if i view the same post URL with the ?__a=1, then it returns the graphql format

@ronaldho Hey can you guide me how are you getting posts URLs from your account, I have searching for media IDs but I could not find any way to get media ids of my posts then I am trying to get posts URLs so I can extract media ids from them.

nfarooq17 avatar Aug 24 '22 03:08 nfarooq17