Import Instagram Data to Google Sheets

In this guide, we’ll walk through how to pull Instagram Insights data data directly into Google Sheets, using the API Connector add-on for Sheets. We’ll be connecting using API Connector’s built-in OAuth2 integration for Instagram Insights (this is a paid feature, please upgrade to access).

Note that to use the Instagram Insights API, you must have an Instagram Business account that is connected to a Facebook Page, and you must be an admin of that Facebook page. If you need help, this guide provides information on converting your personal Instagram account to a business account.

CONTENTS

BEFORE YOU BEGIN

Click here to install the API Connector add-on from the Google Marketplace.

PART 1: CONNECT TO THE INSTAGRAM INSIGHTS API

If you haven’t connected to the Instagram Insights API before, you’ll first need to initiate the connection.

  1. Open up Google Sheets and click Add-ons > API Connector > Manage Connections.
  2. In the list of available connections, find Instagram Insights and click Connect.
    instagram-img2
  3. You will be directed to Facebook and asked to choose which Instagram accounts and Facebook Pages you’d like to use with API Connector. If you are an admin of multiple accounts, make sure to choose the Instagram account and Facebook page that you’ve previously linked together. Click Done.
    instagram-img3
  4. You’ll then be returned to your Google Sheet, and can verify that your Instagram Insights connection is active in the Connections screen.
    instagram-img4

PART 2: CREATE YOUR INSTAGRAM API REQUEST URL

For our first request, we’ll get some basic information about your Instagram account.

  • API root: https://graph.facebook.com
  • Endpoint: /me/accounts (you can optionally include an API version number here)

Putting it all together, we get the full API Request URL.

https://graph.facebook.com/me/accounts

PART 3: PULL INSTAGRAM API DATA INTO SHEETS

We can now enter our values into API Connector and start importing Instagram data into Google Sheets.

  1. Back in the Create Request interface, enter the Request URL we just created above.
    instagram-img1
  2. You don’t need any headers so just leave that section blank.
  3. Under Authentication, choose Instagram Insights from the dropdown menu.
    instagram-img5
  4. Create a new tab and click ‘Set current’ to use that tab as your data destination.
  5. Name your request and click Run. A moment later you’ll see some information about your Instagram account populate your sheet. Pay special attention to the value located in the data » id field as you’ll need it in the next request.
    instagram-img6
  6. Now let’s use that ID to get your Instagram Business account ID, because we’ll need that for all requests to the /insights endpoint, which is what we’re here for! In a new request, create an API URL like this, substituting in your own data ID.
    https://graph.facebook.com/YOUR_DATA_ID?fields=instagram_business_account
  7. Just as you did before, choose Instagram Insights from the Authentication menu (you’ll need to do this for all requests to the Instagram API) and click Run.

    You should now see your Instagram Business account ID printed into the sheet. Keep this handy, we’ll use this ID to get all our Instagram stats!
    instagram-img7

PART 4: EXAMPLE API URLS

You can access the Instagram Insights documentation here (and the full list of available Instagram metrics with their compatible time periods here), but if you just want to get started, you can try the following example URLs, substituting in your own business account ID.

  • Impressions and reach for your Instagram account, for the past 28 days. (Note that the Instagram Graph API returns 2 sets of values, one for the period ending today, and one for the period ending yesterday.)
    https://graph.facebook.com/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=impressions,reach&period=days_28
    instagram-img8
  • Users who have viewed your Instagram business account in the last day.
    https://graph.facebook.com/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=profile_views&period=day
  • A breakdown of cities where your Instagram followers are located
    https://graph.facebook.com/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=audience_city&period=lifetime
    instagram-img9
  • Count of new followers from the prior day
    https://graph.facebook.com/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=follower_count&period=day
  • Metrics by day for a date range (the “since” and “until” parameters contain the start and end dates)
    https://graph.facebook.com/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=impressions,reach,profile_views&period=day&since=1577836800&until=1580428800
The Instagram Insights API requires dates to be entered as UNIX timestamps. In Sheets, you can convert a regular date in cell A1 to a UNIX timestamp with the formula =(A1-DATE(1970,1,1))*86400.

If you want to make a dynamically updating date range, add a dynamic date formula like =today()-1 to one cell, add a second cell that converts it to UNIX with the =(A1-DATE(1970,1,1))*86400 formula, and then reference that UNIX timestamp in your API request URL. Every time the date changes, your URL will update automatically.
  • List of post IDs
https://graph.facebook.com/YOUR_BUSINESS_ACCOUNT_ID/media
  • Key metrics for a specific post (lifetime totals only)
https://graph.facebook.com/POST_ID/insights?metric=impressions,reach,engagement,saved

PART 5: USEFUL LINKS

The Instagram Insights API consists of two endpoints: /{ig-media-id}/insights (metrics on a media object) and /{ig-user-id}/insights (metrics on an Instagram Business or Creator Account). Each endpoint has different available metrics, as described here:

Available Media Metrics: https://developers.facebook.com/docs/instagram-api/reference/media

Available User/Account Metrics: https://developers.facebook.com/docs/instagram-api/reference/user

16 thoughts on “Import Instagram Data to Google Sheets”

  1. Hi, I love this tutorial and it looks it can open one big universe how to get to data from IG and FB. I have troubles with running any requests with metrics, tho. I am able to run the list of the accounts but that’s where I got stuck.

    Once I try to run some metrics request you mentioned above (eg. this one: https://graph.facebook.com/v7.0/380044348695678/insights?metric=audience_city&period=lifetime) , it shows error and nothing happens:

    Request failed: Server responded with an error (400) show response
    {“error”:{“message”:”(#100) The value must be a valid insights metric”,”type”:”OAuthException”,”code”:100,”fbtrace_id”:”AY7XDeLA7BrDwu8TnCJ_Qrp”}}

    Any recommendation what to do?

    Reply
    • Hi Sarka, thank you for the message. I’m not sure why you’re seeing that error, I just went through all the above steps again to test if anything had changed, and didn’t run into any problems. Can you please send me a screenshot of your full request setup in API Connector so I can check if anything looks off?

      Reply
  2. Hey Ana,

    how can i see a day by day breakdown of the last 90 -120 days? i tried to use the “data_preset=last_90d” from FB ads account request, but it didn’t work.

    thank you so much for this post/content.
    – Leo.

    Reply
    • Hi Leo, thank you for the comment. To get data broken down by day you need to use the period=day query parameter. Then, to specify a time range, you need to use the since and until parameters, as a UNIX timestamp as described above. Unlike Facebook’s Insights API, the Instagram Insights API doesn’t support the date_preset parameter, so you need to explicitly specify the date.

      One more wrinkle: in my tests, it seems like since/until can only fetch 30 days at a time, though the documentation doesn’t state that clearly. So, in conclusion, you need to make a few different fetches to retrieve your data. If you plug in your dates and the UNIX conversion formula into a sheet called Inputs, then the following should work (just change your date inputs each time and append data into the same sheet):
      https://graph.facebook.com/v8.0/11111111111111111111/insights?metric=impressions,reach,profile_views,follower_count&period=day&since=+++Inputs!C2+++&until=+++Inputs!C3+++

      Reply
      • Hey Ana, thank you so mucho for your reply.

        I’ve been trying to get the data but i keep getting the same error message: “Request processed. No records found”. In this case it’s unlikely given that the account is al least 2 years old. i’ve reduced the date range, used the Inputs sheet as you recommended, but still can’t get the data.

        have you run into this problem in the past?

      • Hi Leo, sorry it’s still not working. I haven’t seen this error with this specific API, but I’ve definitely run into this type of problem before (I think I’ve run into every possible problem at this point :p)

        Are you able to get data from any of the requests? For troubleshooting something like this, it’s usually best to start off with very simple requests (e.g. one day, one metric) and add complexity from there. That way we can try to identify (or rule out) if it’s related to the account ID, to the metric combination, to the date range, etc. If you can share your URL or sheet, I’ll be happy to take a look as well.

  3. Hi, Ana! Is it possible to recieve aggregated engagement data from all posts?

    I use this request – https://graph.facebook.com/v8.0/ig-user-id/insights?metric=engagement&period=day

    but it shows an error:

    “metric[0] must be one of the following values: impressions, reach, follower_count, email_contacts, phone_call_clicks, text_message_clicks, get_directions_clicks, website_clicks, profile_views, audience_gender_age, audience_locale, audience_country, audience_city, online_followers”

    As i understand it works only with ig-media-id instead of ig-user-id. In this way how to create automated scheduled reports for engagement metric?

    Reply
    • Hey Michael, based on what I see here, it looks like you can only get it for individual posts, not aggregated at an account level. So I think you have to do the following:
      1) get a list of your post IDs by running this query: https://graph.facebook.com/v9.0/YOUR_ACCOUNT_ID/media

      2) now substitute in those IDs into this query: https://graph.facebook.com/v9.0/YOUR_POST_ID/insights?metric=engagement,impressions,reach

      To run through a list of IDs, you can reference a range of cells like this: https://graph.facebook.com/v9.0/+++IDs!A2:A10+++/insights? metric=engagement,impressions,reach

      Then you will have engagement metrics for all the posts on your list, and can calculate the overall rate yourself. Can you please check if that would work for you?

      Reply
      • It works, but only for a lifetime period.

        I tried to add ‘period’ or ‘since/until’ to the queries, but it shows incompatible error. It looks like there’s no way to get monthly or daily engagement because of Instagram API limitations.

        But thank you anyway for answers!

      • Bummer, I just investigated this further and confirmed your findings. The Instagram API doesn’t provide any way to slice up the media insights by time, it’s all lifetime totals only. The /{ig-user-id}/insights endpoint does provide time slicing capabilities, but you can’t get the engagement metric there.
        Sorry for the inconvenience, I’ll update the post with some of these findings.

    • Hey Eddy, I don’t have any templates for Instagram but am happy to help you set up some requests to get data. Are there specific metrics you’re looking for?

      Reply
  4. Hi!
    Thank you for your post. I’m having the following error starting Part IV

    Status
    Completed with errors
    – Server responded with an error (400) show response

    ‘show response’ = {“error”:{“message”:”(#100) Tried accessing nonexisting field (insights) on node type (Business)”,”type”:”OAuthException”,”code”:100,”fbtrace_id”:”AdvCGsGT8eVdy5vECPellEV”}}

    Reply
    • Hi Leandro, I haven’t seen this error before so I can’t say for sure, but based on that error message it sounds like Facebook’s API has a problem providing insights data for that account ID. I would double-check some of the requirements: can you please confirm that your Instagram account is a public business or a creator account, that it’s connected to a FB page that you’re the admin of, and that the Instagram account has more than 100 followers?

      Reply
    • Hi there, sorry you’re having trouble getting connected. Can you say a little more about what kind of error message you’re getting?

      Reply

Leave a Comment