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: https://help.instagram.com/502981923235522?helpref=page_content

CONTENTS

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 > Create New API Request.
  2. Under Authentication, click Manage connections.
    quickbooks-img1
  3. In the list of available connections, find Instagram Insights and click Connect.
    instagram-img2
  4. 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
  5. 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: /v7.0/me/accounts

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

https://graph.facebook.com/v7.0/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. Let’s call it ‘IG1’ to mark that it’s our initial Instagram request. Click ‘Set’ 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.
    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 (this example references the output from the original request through the +++ syntax, but if you prefer you can just directly enter the value from the data » id field).
    https://graph.facebook.com/v7.0/+++IG1!F2+++?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 printed into the sheet. Keep this handy, we’ll use this ID to get all our Instagram stats!
    instagram-img7

PART 4: MORE 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/v7.0/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/v7.0/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=profile_views&period=day
  • A breakdown of cities where your Instagram followers are located
    https://graph.facebook.com/v7.0/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=audience_city&period=lifetime
    instagram-img9
  • Count of new followers from the prior day
    https://graph.facebook.com/v7.0/YOUR_BUSINESS_ACCOUNT_ID/insights?metric=follower_count&period=day
  • Metrics by day for a date range
    https://graph.facebook.com/v7.0/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.

6 thoughts on “Import Instagram Data to Google Sheets”

  1. I’m lost on what I’m supposed to do on Step 6 to Step 7. There were no instructions on what to click and where going to Step 7. Thanks.

    Reply
    • Sorry about that, you’re right, I didn’t mention that you need to click “Run” to make the request run. I’ll update the article to make that clearer!

      Reply
      • Thank you.

        Now I’m getting prompt “Status: Request processed, no records found” after clicking Run.
        I’m guessing it has something to do with naming API Request Based on a Cell
        I tinkered and tried the Tab name and I get “Status: Request failed: Server responded with an error (400)”

        I don’t understand the naming conventions. What does IG1 mean in the API URL in Step 11?

      • I’m not sure why you’re getting that result. Can you get data back for any of the requests?
        As for the naming, you can name them however you like, it’s just easier to follow along if you use the same names I use. I picked “IG1” for the name because “IG” = Instagram, and “1” marks that it’s the first request. But again, feel free to name it however you like. You also don’t have to base the API request on a cell, for me it’s easier that way, but you can just enter in the text directly if you prefer.
        If you’re still having trouble, feel free to share your sheet with support @ mixedanalytics.com and I can check it for you.

  2. I get the error:
    {
    “error”: {
    “message”: “(#100) Page Public Metadata Access requires either app secret proof or an app token”,
    “type”: “OAuthException”,
    “code”: 100,
    “fbtrace_id”: “AgHkgTPXz4D1SOW5mmjo_5X”
    }
    }
    at step 7. Can you give an advise?

    Reply
    • Sorry, it looks like there’s an additional scope required. I’ve added the pages_read_engagement scope, which should resolve the issue. Please try again at your convenience.

      Reply

Leave a Comment