Reputation: 372
I am attempting to make an API request using the Facebook Graph API for an Instagram businesses posts.
https://developers.facebook.com/docs/instagram-api/business-discovery
Using Facebook's Graph API Explorer I am calling
<my_facebook_page_id>?fields=business_discovery.username(<instagram_business_account_username>){media{comments_count,like_count, caption, media_url, media_type,timestamp}}
This successfully returns the 25 most recent posts from the Instagram business account along with an "after" field in the paging > cursor section of the json.
However, I'm now trying to use some form of pagination to get the next 25 posts.
I've read that the Facebook Graph API supports Cursor and Time-based pagination, but the following article suggests that the /media endpoint for Business Discovery only supports Cursor based pagination.
https://developers.facebook.com/docs/instagram-api/reference/user/business_discovery#pagination
I've tried several variations of the above query in an attempt to get the next 25 posts but all of them return the most recent 25 posts (the same as the initial query above did).
Here are some examples of queries I've tried.
<my_facebook_page_id>?fields=business_discovery.username(<instagram_business_account_username>){media{comments_count,like_count, caption, media_url, media_type,timestamp}}&after=<after_code_from_first_call>
<my_facebook_page_id>?fields=business_discovery.username(<instagram_business_account_username>).after(<after_code_from_first_call>){media{comments_count,like_count, caption, media_url, media_type,timestamp}}
So any help in how to format these query strings in order to perform pagination for instagram media objects (either using the after/before parameters, timestamps or post_ids) would be very much appreciated.
Thanks.
Upvotes: 4
Views: 4362
Reputation: 31
I have tested the accepted answer (@Tom C) on Jun 4, 2024, and it still works. It has the ability to control the limit of the amount of posts per request, which can be quite useful if you have a large number of posts and low rate limit. BTW, the positions of limit and after can be changed as well:
https://graph.facebook.com/v3.0/<my-facebook-page-id>?access_token=<access-token>&fields=business_discovery.username(<accountHandle>){{profile_picture_url,media.limit(<the-amount-of-posts-to-return>)after(<pagination-code>).{{id,caption,media_url,media_type,like_count,comments_count,timestamp,permalink}}}}
Upvotes: 0
Reputation: 45
I've tried the accepted answer's solution but it doesnt work (maybe because of the graph version) here is the working API request on v17.0
https://graph.facebook.com/v17.0/{ig-user-id}?access_token={access-token}&fields=id,business_discovery.username({username}){media.after({pagination-code}){id,comments_count,like_count}}
Note: its also work with cursor/time/based pagination, see supported parameter here
Upvotes: 1
Reputation: 372
After a lot of trial an error, I figured out the correct format for the API request should be as follows
https://graph.facebook.com/v3.0/<my-facebook-page-id>?access_token=<access-token>&fields=business_discovery.username(<accountHandle>){{profile_picture_url,media.after(<pagination-code>).limit(<the-amount-of-posts-to-return>){{id,caption,media_url,media_type,like_count,comments_count,timestamp,permalink}}}}
I have also found that there is no limit to the amount of posts that can be returned (I managed to return 1000 at once in testing)
Note: the "pagination-code" is the "after" code that is provided when you do an API call.
Upvotes: 17