skip to Main Content

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:

  1. Retrieved Facebook account access token using the Graph API.

  2. Retrieved all the user accounts/pages using the access token.

  3. Upon selection of the Facebook page checking if the Instagram account is linked to that page using the access token.

  4. Using the Instagram account id I am able to fetch the following:

'/accountID?fields=follow_count,followed_by_count,media_count,id'
  1. 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


  1. Chosen as BEST ANSWER

    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 via Business Meta


  2. To get the fields like followers_count, follows_count, media_count your 4th step should be:-

    GET https://graph.facebook.com/v17.0/{ig-user-id}?fields=followers_count,follows_count,media_count,id
    

    and it will create a response something like this:-

    {
      "followers_count": 0,
      "follows_count": 0,
      "media_count": 1,
      "id": "1784144XXXXX"
    }
    

    To get IG Media insights, your 5th step should be:-

    GET https://graph.facebook.com/v17.0/{ig-media-id}/insights?metric=impressions,engagement&limit=10
    

    and it will return the response like the below:-

    {
      "data": [
        {
          "name": "impressions",
          "period": "lifetime",
          "values": [
            {
              "value": 0
            }
          ],
          "title": "Impressions",
          "description": "Total number of times the media object has been seen",
          "id": "17993550XXXXXX/insights/impressions/lifetime"
        },
        {
          "name": "engagement",
          "period": "lifetime",
          "values": [
            {
              "value": 0
            }
          ],
          "title": "Engagement",
          "description": "Total number of likes and comments on the media object",
          "id": "17993550XXXXXX/insights/engagement/lifetime"
        }
      ]
    }
    

    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::-

    GET https://graph.facebook.com/v17.0/{ig-user-id}/media
    

    and the response would look something like this:-

    {
      "data": [
        {
          "id": "17993550XXXXXX"
        }
      ],
      "paging": {
        "cursors": {
          "before": "QVFIUkdGRXA2eHNNTUsZAXNGFxQTAtd3U4QjBLd1B2NXRMM1NkcnhqRFdBcEUzSDVJZATFoLWtXMWZAGU2VrRTk2RHVtTVlDckI2NjN0JrUk4yMW13",
          "after": "QVFIUmlwbnFsM3N2cV9FdCa0hDeV9qMVliT0VuMmJyNENxZA180c0t6VjFQVEJaTE9XV085aU92OUFLNFB6Szd2amo5aV9rTlVBcnmEtxcE1HSFR3"
        }
      }
    }
    

    I hope this will help.

    Source:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search