Search code examples
facebook-graph-apiinstagraminstagram-api

Is it possible to request Instagram metrics with different periods in a single API call?


I would like to request the following Instagram Insights metrics using a single graph API call:

  • follower_count
  • audience_gender_age

The problem I am facing is that follower_count requires a period parameter 'day' and audience_gender_age a period parameter 'lifetime'. I have tried to merge them in a single API call, but this is not supported by Facebook:

/XXXXXX/?fields=insights.metric(follower_count).period(day),insights.metric(audience_gender_age).period(lifetime)

I there a proper way to request these metrics using different periods in a single API call?


Solution

  • If you need to request data from the same field twice in one query, that can be done using the .as(name) aliasing syntax, https://developers.facebook.com/docs/graph-api/aliasing-fields

    Quote docs,

    For example, you can retrieve an image in two sizes and alias the returned object fields as picture_small and picture_larger:

    me?fields=id,name,picture.width(100).height(100).as(picture_small),
              picture.width(720).height(720).as(picture_large)