I am writing social integration class for Facebook & Instagram. Facebook is done using PHP SDK and Graph API now struggling with Instagram. I followed the following procedure:
-
Retrieved Facebook account access token using the Graph API.
-
Retrieved all the user accounts/pages using the access token.
-
Upon selection of the Facebook page checking if the Instagram account is linked to that page using the access token.
-
Using the Instagram account id I am able to fetch the following:
'/accountID?fields=follow_count,followed_by_count,media_count,id'
- When trying to fetch this:
'/accountID/media?fields=insights.metric(engagement,impressions)&limit=10'
I am getting this as a response:
(#100) Tried accessing nonexisting field (media) on node type (InstagramUser)
Tried Instagram Basic Display API also but using that I can’t fetch followers_count
or followed_by_count
tried with multiple permissions and also tried to search in Facebook Docs but as of yet don’t have any clue.
2
Answers
I solved the problem and noticed that
fb_page_id/instagram_business_account
end-point wasn't returning any instagram user id because the page was connected with instagram using page setting whereas it was require to be connected viaBusiness Meta
To get the fields like
followers_count
,follows_count
,media_count
your 4th step should be:-and it will create a response something like this:-
To get IG Media insights, your 5th step should be:-
and it will return the response like the below:-
To get the
ig-media-id
, you need to call to the following endpoint and it will return the IDs of all the IG Media objects on the IG User::-and the response would look something like this:-
I hope this will help.
Source: