Import Facebook Page Data to Google Sheets

Import Facebook Page Data to Google Sheets

Last Updated On August 20, 2019
You are here:
< Back

Facebook Pages serve as a business presence for many companies, displaying product info, reviews, posts, and more. In this guide, we’ll walk through how to pull Facebook fan page data from the Facebook API directly into Google Sheets, using the free API Connector add-on.

Note that the process for getting Facebook access tokens isn’t difficult, but it is rather long and can be confusing as there are several kinds of tokens: User Access Tokens, App Access Tokens, and Page Access Tokens. Further, tokens are valid for different lengths of time, and Page Access Tokens are dependent on User Access Tokens. There are many different approaches to retrieve these tokens, but the following method should be the most straightforward.

PART 1: GET YOUR FACEBOOK API USER ACCESS TOKEN

  1. Begin by navigating to https://developers.facebook.com/, and click Create App.
    fb-img1
  2. Fill out your details and click Create App ID. You can call your app anything, but in this example we’ll call it Google Sheets.
    fb-img2
  3. You’ll be directed into your Developer dashboard. You don’t need to do anything in this dashboard. Instead, open up the Facebook Graph API Explorer
  4. Click Get User Access Token from the drop-down menu
  5. fb-img3

  6. A modal will appear prompting you to select the permissions you wish to access. For this example, make sure you’ve at least selected “manage_pages” and “read_insights”. Click Get Access Token.
    fb-img4
  7. You’ll be prompted to log in and select the pages which you’d like to access via the API.
    fb-img5
  8. Click through, ignoring any prompts to “Submit for Login Review”. We don’t need to worry about that for now.
    fb-img6
  9. You should now see your first access token. However it only lasts for 1 hour. We can extend it by clicking the small blue icon next to the short-lived access token, and then clicking Open in Access Token Tool (link).
    fb-img7
  10. At the bottom of this page, click Extend Access Token.
    fb-img8
  11. This will produce a long-lived token. Click Debug to view the whole string and copy it to your clipboard. We’ll need it in a moment.
    fb-img9

PART 2: GET YOUR FACEBOOK API PAGE ACCESS TOKEN

  1. You’ll first need your Facebook Page ID. Again, there are a few ways to get this, but the easiest is to open up your Facebook page and right-click on your profile picture. Click Save Link As, and paste the results into Notepad or similar. The URL should look like this:
    https://www.facebook.com/507738226062106/photos/868775829958342/
    Note the highlighted part. This is your Facebook Page ID.
  2. Return to the Facebook Graph API Explorer. Paste the long-lived token into the “Access Token” field, and make a GET request to {page ID}?fields=access_token, making sure to substitute in your own page ID where it reads {page ID}. In this example it would be 507738226062106?fields=access_token, as shown in the screenshot below.
    Click Submit and you will see your permanent Page Access Token returned in the response.
    fb-img10
  3. Congrats, you have your Page Access Token! You’re now ready to pull Page data out of Facebook’s API.

PART 3: CREATE YOUR API REQUEST URL

We’ll first follow the Facebook documentation to access the latest posts from your Page.

  • API root: https://graph.facebook.com/v4.0/
  • Endpoint: {Page ID}/feed
  • Endpoint Example: 507738226062106/feed
  • Query Strings: ?access_token={Page Access Token}

Putting it together, we get the full API Request URL:
https://graph.facebook.com/v4.0/507738226062106/feed?access_token={Page Access Token}
Note that you need to substitute in your own Page Access Token where it reads {Page Access Token}. Your Page Access Token is the value you retrieved at the end of Part 2.

PART 4: ENTER YOUR VALUES INTO API CONNECTOR

We can now enter all our values into API Connector and import Page Post data into Google Sheets.

  1. Open up Google Sheets and click Add-ons > API Connector > Create New API Request.
  2. In the Create Request interface, enter the Request URL we just created. Leave the Headers selection blank, set a data destination, and click Run. A moment later you should see your most recent posts populate your Google Sheet.

    fb-img11

  3. Experiment with endpoints and query strings as described in the documentation to see other types of page data. For example, you can access Page Insights by changing the API URL to https://graph.facebook.com/{page ID}/insights?metric=page_fan_adds_unique,page_fan_adds&access_token={Page Access Token}.
    Again, remember to substitute in your actual Page ID and Page Access Token where it reads {page ID} and {Page Access Token}.
    fb-img12

Comments:0

Leave a Reply

Your email address will not be published.