Search code examples
facebookfacebook-graph-apiinstagraminstagram-api

How to get Instagram post URL from Facebook Graph media_id


I'm using Instagram Mentions API and was able to obtain FB media_id for couple Instagram posts.

I need media_id to get post content via /user/mentioned_media. Unfortunately that endpoint does not provide ig_id or shortcode or permalink which I need.

Is there a way to get Instagram Post URL with FB Graph API media_id?


Solution

  • if you check the documentation for GET /{ig-user-id}?fields=mentioned_media at https://developers.facebook.com/docs/instagram-api/reference/ig-user/mentioned_media , it says that fields is for a IGMedia node, even though its not docummented properply in the above url, you can use the available fields of an IGMedia Node as described here https://developers.facebook.com/docs/instagram-api/reference/ig-media.

    Hence you can get the permalink by asking for it in the fields param like this

    https://graph.facebook.com/v16.0/{YOUR_IG_USER_ID}?fields=mentioned_media.media_id(18024497428601371){id,caption,permalink,media_url}
    

    and you get a graph api response

    {
      "mentioned_media": {
        "id": "18024497428601371",
        "caption": "example text",
        "permalink": "https://www.instagram.com/p/SHORT_CODE/",
        "media_url": "SOME_URL"
      },
      "id": "YOUR_IG_USER_ID"
    }
    
    

    P.S It will also only work if the user has mentioned your ig account in the media caption