Facebook Page API data in Google Sheets

How to connect Facebook Pages API to Google Sheets

The Facebook Pages API allows apps to access and update a Facebook Page’s settings and content, create posts, get post data, get comments data on page owned content, get page insights, update actions that users are able to perform on a page, and much more.

API authentication for the Facebook Page API is handled through Access Tokens. Most endpoints require Page access tokens, which are unique to each Page, app user, and app, and have an expiration time. In order to get a token from an app user, the app user must own or be able to perform a Task on the Page.

In this tutorial, I’ll show you how to connect the Facebook Pages REST API to Google Sheets in 6 steps using the Apipheny Google Sheets add-on:

  1. Install the Apipheny Add-on
  2. Create a Facebook App
  3. Get your Access Token
  4. Get the endpoint URL
  5. Add the URL into the Apipheny Add-on
  6. Run the Facebook Page API Request

Step 1.) Install and open the Apipheny add-on for Google Sheets

To pull data from the  Facebook Pages API to Google Sheets easily and without writing any code, first install and open the Apipheny Google Sheets add-on. Apipheny is a no-code API integrator for Google Sheets that you can use to make unlimited API requests, connect to unlimited APIs (including the Facebook Pages API), save API requests, schedule API requests, and more. Click here if you want to learn more about Apipheny.

1.) Install Apipheny by clicking the Install button on this page.

2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Add-Ons button in the top menu.

When the Add-ons menu opens, you should see Apipheny. Click Apipheny > Import API to open the Apipheny sidebar as shown here:

Step 2.) Create a Facebook App

1.) Begin by navigating to https://developers.facebook.com/ and click My Apps > Create App:

2.) Fill out your details and click Create App ID. You can call your app anything, but in this example we’ll call it ApiphenyApp:


3.) You’ll then be directed to your Developer dashboard. You don’t need to do anything in this dashboard. Instead, click Tools, then Facebook Graph API Explorer:


4.) Click Get User Access Token from the User Tokens drop-down menu:

5.) Click the Add a Permission field to search for permissions you want to add, or click in the section beneath this field to select them from a list. For this example, make sure you’ve selected at least the manage_pages and read_insights permissions:

6.) After you’ve selected the permissions, click the Generate Access Token button.

You will be asked to approve your permission through App Review. If you have a role, like admin, developer or tester, then you can click the Done button and move forward, because this action isn’t needed.

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 this short-lived access token, and then in the pop-up, clicking the Open in Access Token Tool button:

7.) The Access Token Debugger will open at the bottom of the page, then click Extend Access Token:

8.) This will produce a long-lived token. Click Debug to view the whole value and copy it to your clipboard, as we’ll need it in a moment:

Step 3.) Get your permanent Facebook Pages API Access Token

1.) Navigate back to the Facebook Graph API Explorer. Paste the long-lived token you just got into into the “Access Token” field:

2.) Enter {page ID}?fields=access_token into the URL field, making sure to substitute {page ID} with your own Page ID.

👉 To get your Facebook Page ID, open up the Facebook page you want to connect, and click About in the menu on the left. Then scroll down and you will see the Page ID listed.

In this example, the URL is 109868280670999?fields=access_token, as shown in the screenshot below. After adding your URL, click Submit:

3.) After you click Submit, you’ll see your permanent Page Access Token returned in the response. Copy this value (shown in green text below) somewhere safe, so that you won’t have to go through the same process again:

Step 4.) Get a Facebook Page API URL endpoint

To find descriptions and examples for the different Facebook Pages API endpoints you can use, go to the relevant section of the Graph API documentation at:

https://developers.facebook.com/docs/graph-api/reference/v6.0/page

On that page, in the menu on the left, in the Reference section, you will find the list of available endpoints. You can also run a search for an endpoint in the Search bar if you can’t easily spot the one you need in the list.

Select any of the endpoints and the corresponding documentation page will be opened. For instance, this is how the Page Feed endpoint looks like:

Facebook API Page Feed Endpoint Documentation
Facebook API Page Feed Endpoint Documentation

If you want to use the same example URL endpoint as us, continue to the next step.

Step 5.) Add your Facebook Pages API URL into the Apipheny add-on

After you get the endpoint that you need, copy the complete URL into the Apipheny add-on, where it says API URL Path, followed by any GET parameters required for your query, like this.

The Facebook API URLs generally have this format:

https://graph.facebook.com/{API Version}/{Page ID}/{Endpoint Path}?access_token={Access Token}

You will have to replace the placeholders with the latest API version (6.0 currently), your own Page ID, the endpoint’s URL and the Page Access Token we obtained in the previous step.

At the top of the Apipheny sidebar, select the HTTP method (GET or POST) as required by your API endpoint. In this example we are using GET, as you can see in the screenshot below.

In this example we accessed the latest posts from the Page, using the feed endpoint:

https://graph.facebook.com/v6.0/109868280670999/feed?access_token=EAAIYVB...

Insert the API Request URL into the Apipheny API URL Path field then click Run:

You don’t need to add anything else in the add-on besides the URL.

Step 6.) Run the Facebook Pages API Request in Google Sheets

Click the Run button at the bottom of the Apipheny add-on and then wait for the Facebook Pages data to be fetched and added to your Google Sheet:

Facebook Page API data in Google Sheets

After making a successful request to the Facebook Page API, try querying a different endpoint, or try using one of the more advance features in the Apipheny add-on, such as:

  • Save and schedule your API request
  • Make a POST request to the Facebook API (if available).
  • Use the custom =APIPHENY() function to call the API request inside your spreadsheet
  • Create an API request by referencing the value of a cell in the API URL (with three curly braces eg. {{{Sheet1!A1}}}

Related articles:

Related Posts

Leave a Comment