9

I'm looking for a way to fetch Media Insights metrics in Instagram Graph API (https://developers.facebook.com/docs/instagram-api/reference/media/insights) with a nested query based on the userId, even when a client switched from a Personal to a Business account.

I use this nested query to fetch all the data I need : https://graph.facebook.com/v3.2/{userId}?fields=followers_count,media{media_type,caption,timestamp,like_count,insights.metric(reach, impressions)} (this part causes the error: insights.metric(reach, impressions) - it works however for an account that has always been a Business one)

However, because some media linked to the userId were posted before the user switched to a Business account, instead of returning the data only for the media posted after, the API returns this error:

{
    "error": {
        "message": "Invalid parameter",
        "type": "OAuthException",
        "code": 100,
        "error_data": {
            "blame_field_specs": [
                [
                    ""
                ]
            ]
        },
        "error_subcode": 2108006,
        "is_transient": false,
        "error_user_title": "Media Posted Before Business Account Conversion",
        "error_user_msg": "The media was posted before the most recent time that the user's account was converted to a business account from a personal account.",
        "fbtrace_id": "Gs85pUz14JC"
    }
}

Is there a way to know, thru the API, which media were created before and after the account switch from Personal to Business? Or is there a way to fetch the date on which the account was switched?

The only way I currently see to get the data I need is to use the /media edge and query insights for each media until I get an error. Then I would get approximately the date I need. However, this is not optimized at all since we are rate limited to 200 calls per user per hour.

4 Answers4

3

I have the same problem.

For now, I'm Switch between queries (if first have error)

"userId"?fields=id,media.limit(100){insights.metric(reach, impressions)}

"userId"?fields=id,media.limit(100)

I show the user all insights in zero.

I don't know if they're the best alternative, like identify the time of conversion to business and get the post between this range of DateTime

Sina
  • 270
  • 1
  • 23
2

I got the same problem and solved it like this:

  • Use the nested query just like you did, including insights.metric
  • If the error appears, do another call without insights.metric - to at least get all other data

For most accounts, it works and there is no additional API call. For the rest, i just cannot get the insights and i have to live with it, i guess - until Facebook/IG fixes the issue.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
0

I got the same problem and solved it like this:

Step1: Convert your Instagram account to a Professional account.

Step2: Then According to Error Post a new post on Instagram and get their Post-ID.

Step3: Then try to get a request using that Post-ID.

{Post-ID}?fields=comments_count,like_count,timestamp,insights.metric(reach,impressions)

curl -i -X GET "https://graph.facebook.com/v12.0/{Post-ID}?fields=comments_count%2Clike_count%2Ctimestamp%2Cinsights.metric(reach%2Cimpressions)&access_token={access_token}"

For more: insights

akSingh
  • 21
  • 2
0

Here is the relevant logic from a script that can handle this error while still doing a full import. It works by reducing the requested limit to 1 once the error is encountered. It will keep requesting insights until it encounters the error again, then removes insights from the fields and returns to the requested limit.

limit = 50
error_2108006 = False
metrics = 'insights.metric%28impressions%29%2C' # Must be URL encoded for replacement
url = '/PAGE_ID/media?fields=%sid,caption,media_url,media_type&limit=%s' % (metrics, limit)

# While we have more pages
while True:

    # Make your API call to Instagram
    posts = get_posts_from_instagram(url)

    # Check for error 2108006
    if posts == 2108006:

        # First time getting this error, keep trying to get insights but one by one
        if error_2108006 is False:
            error_2108006 = True
            url = url.replace('limit={}'.format(limit), 'limit=1')
            continue

        # Not the first time. Strip out insights and return to desired limit.
        url = url.replace(metrics, '')
        url = url.replace('limit=1', 'limit='.format(limit))
        continue

    # Do something with the data
    for post in posts:
        continue

    # If there are more pages, fetch the next URL
    if 'paging' in posts and 'next' in posts['paging']:
        url = posts['paging']['next']
        continue

    # Done
    break
dotcomly
  • 2,154
  • 23
  • 29