-1

Facebook recently changes its Instagram API. Now I can get all the media ids by requesting from this endpoint-

https://graph.facebook.com/v7.0/{ig-user-id}/media?access_token=...

But it only returns the media Ids, not any other media information such as caption, media_url, comments_count, likes_count etc.

For getting these data, I have to request from the API-

https://graph.facebook.com/v7.0/{ig-media-id}?fields=caption,media_url,comments_count&access_token=...

This is working well but the problem is I have to hit this API for each and every {ig-media-id} which is not a good thing.

So, is there any way to get all the media with information (caption, media_url, comments_count, likes_count) by one API request like-

 https://graph.facebook.com/v7.0/{ig-user-id}/media?fields=caption,media_url&access_token=...
Sajeeb Ahamed
  • 6,070
  • 2
  • 21
  • 30
  • https://developers.facebook.com/docs/graph-api/using-graph-api#field-expansion, https://developers.facebook.com/docs/graph-api/advanced#fieldexpansion – CBroe Jul 08 '20 at 08:07
  • Thank you @CBroe for your comment. You may misunderstand me. The first endpoint at my question returns the media but it only returns the `ids`. For getting the detail of a media I have to hit the 2nd endpoint. And suppose I am trying to get 8 media and for that I have to hit the 2nd API 8 times. So my question is how could I get the media with details by one API hit. – Sajeeb Ahamed Jul 08 '20 at 08:56
  • No, I did not misunderstand you. – CBroe Jul 08 '20 at 09:02
  • 1
    @CBroe could you please write an answer? – Sajeeb Ahamed Jul 08 '20 at 09:19

2 Answers2

1

I solve the problem using Nested Request. Special thanks to @Cbroe.

I've gained the result by using one query after changing the 1st API like this-

https://graph.facebook.com/v7.0/{ig-user-id}?fields=media.limit(4){id,caption,media_url}&access_token=...
Sajeeb Ahamed
  • 6,070
  • 2
  • 21
  • 30
0
https://graph.instagram.com/<version(optional)>/me/media?fields=<fields-to-be-retrieved>&access_token=<your-access-token>&limit=<limit-number-of-responses(optional)>

the above endpoint (replace placeholders with actual values) gets all the media associated with a user (you have to use paging for large data set), you can generate long-lived access token from access token generator.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 28 '23 at 11:08