Search code examples
facebook-graph-apirestfb

Interacting with Instagram accounts directly via FB graph API


I'm trying to create an endpoint that can independently determine the total number Instagram accounts associated with a Meta login and page through the results independently of Facebook pages.

Currently, if I had a Facebook account with 150 Facebook business pages and 3 Instagram pages, totalCount would return 150, and if I were querying the API with a limit of 5, I'd need to make 30 queries just to find those 3 instagram pages. When I provide a parameter for instagram_business_account and don't include facebook pages, I'd like to be able to get back all 3 of those instagram accounts on the first result, and get the information that there are only 3 instagram accounts, without needing to go through every page.

I understand that this may be due to Instagram accounts being linked to Facebook business pages. I'd appreciate any workaround that might allow me to retrieve the Instagram accounts without needing to query so many Facebook pages, which is causing very slow response for users who want to see their Instagram pages aggregated independently of Facebook.


Solution

  • The instagram business account is linked to the Facebook page and I only know the way using me/accounts to get all the instagram ids.

    But you can improve the request.

    Try something like: me/accounts?fields=instagram_business_account,access_token,name&limit=100

    So you reduce the fields to the necessary ones and change the limit to a higher number to fetch more accounts in one call. You have to try the maximum number supported, but I think you can fetch everything with 2-3 calls instead of 30. This should speed up the process a lot. I would start with the 150 and reduce the limit if the call is not working. Afaik the limit depends on the call and my change if Facebook likes to change them. So a failure safe implementation is the best way to go.

    If you need the data more often, you can cache them and perhaps let the user trigger a refresh. I don't know the use case or your user base, but this may lead to an even better user experience.