2

how can I get the media-id of a instagram posting from the url?

For example I need the media-id for https://www.instagram.com/p/Cf4dPucLzW0/

Solutions that does not work anymore:

  • Oembed dont give media-id back
  • adding ?__a=1 to a link redirects me to the post itself
penguin_P
  • 63
  • 5

2 Answers2

3

Put the following at the end of the post: ?__a=1&__d=dis, e.g.:

https://www.instagram.com/p/Cf4dPucLzW0/?__a=1&__d=dis

dbc
  • 104,963
  • 20
  • 228
  • 340
0

you need to have pageid, access token and an short code (which can be extracted from the URL you have for eg if this is the url :https://www.instagram.com/reel/Cs12TgIv8Ns/. "Cs12TgIv8Ns" is the short code)

  1. then you can use the page id to convert to instagram business id using the following url: url = Graph + endpoint + '?fields=' + instagram_business_account + '&access_token=' + Token

  2. convert the short code to

    alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
    media_id = 0
    for letter in short_code:
        media_id = (media_id * 64) + alphabet.index(letter)
    IG_id_list.append(str(media_id))
  1. then use the following url to get various metrics and media id https://graph.facebook.com/v11.0/{instagram_business_account_id}/media?fields=....&access_token=token