Facebook Insights

In order for Keboola to be able to get your data, we need two things, the page id, and your account token.

To get the account token:
1. Log into your facebook account that has the administrative privileges to the page you would like to track stats on
2. Follow the link here and copy the token.  Give this token to your Keboola Consultant.
**Note** Facebook tokens expire every 2 months.  Unfortunately there is no way around this so far.  You will need to reauthorize KBC using this link every 2 months. 

To get the page id:
1. Go to your facebook page's URL.  For example, if you are getting stats for the fan page "Facebook", this is the page's URL you need.
2. Copy and paste the link using this website.   (For example, use the url for the facebook link above, and paste it in the website referenced).
3. Copy and give this page id to your Keboola Consultant for each page id that you want the stats for. 

==================================================================
Never expiring access token

This description did work to change access token from expiring at some point in time to never expiring.

https://www.rocketmarketinginc.com/blog/get-never-expiring-facebook-page-access-token/   (Check updated 2016 version)
  1. Go to https://developers.facebook.com/tools/explorer
  2. Select your applications from the dropdown on the top right hand side
  3. Click “Get Access Token” button just below the application drodown on the right hand side
  4. In the dropdown select the page you want to get a access token for.  If you don’t see your pages listed then you’ll need to make sure you’re set with the admin role for the page. Also you may have to click “Get Page Access Token” in the dropdown, after which then your pages will show in the dropdown next time you click the “Get Access Token” button.
  5. In the “Access token” input field click the blue exclamation point icon
  6. In the popup click the “Open in Access Token Tool” button on the bottom left of the popup
    open-in-access-token-tool
  7. This will open a new page with that app’s access token details. You’ll most likely see the token only lasts for an hour or so
  8. At this point in our case token for some reason already showed as generated a minute ago and promising to never expire
  9. To extend that token and get one that doesn’t expire, click the “Extend Access Token” button
  10. That will give you a never expiring access token
==================================================================

RECREATING STANDARD FACEBOOK REPORTS VIA API

Intro and general description

For this project we were required to recreate standard Facebook reports by extracting data through API.

List of metrics requested by customer and their API equivalents are in a file attached (Facebook standard reports API).


Facebook Graph API descriptions could be found by the link:

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

* This guide is written for Version 2.8. Some metrics will require mention of a version in a call.


All documentation about Keboola Facebook extractor is kept here:

http://wiki.keboola.com/home/keboola-connection/user-space/extractors/extractors/facebook-insights

In this guide only steps for a particular project described.

Configuration of Facebook extractor

Facebook extractor configurations are kept in csv tables in sys.c-ex-facebook bucket. In order to create a Facebook extractor, first need to have config tables in the storage to refer to.


First table would be authorization config. Table will be names accounts and have next columns:

Order (just 1 if one account), id (FB account id), name (FB account name), token (authorization token), valid (put 1 for valid), user (id of user that authorized access to account). Full instructions on Keboola wiki:

http://wiki.keboola.com/home/keboola-connection/user-space/extractors/extractors/facebook-insights#Extractor_Configuration


Next we create config tables for extractors. We used two types of data imports - regular and pivoted. Regular would provide table with metrics as rows - there would be a column Metric and each record will specify metric and have one value. Pivoted calls return tables with metrics as columns - there will be a column for each metric where each row will have one value. Pivoted tables are much easier to work with so we tried to use as many metrics for Pivoted calls as possible, but it was not always possible (specifically for calls that return arrays of values). More description on Wiki:

http://wiki.keboola.com/home/keboola-connection/user-space/extractors/extractors/facebook-insights#API_Call_Types


In our project we had three configurations:

insightsPages_pivoted, insightsPosts_pivoted, insightsPosts

All three configurations attached. To review them use resources mentioned in the top of this guide.

Registration of Facebook extractor

For every configuration in sys bucket (except accounts) you will need to register a Facebook extractor. To do so you need to do a POST call to:

https://connection.keboola.com/v2/storage/components/ex-facebook/configs

In the header enter key “X-StorageApi-Token” and Keboola storage token as value.

In the body:

For configurationId value enter name of a table with config in sys bucket. Value for name will be the name of your new extractor.


Once extractor created - you may change content of config table as many times as needed loading into the same table.

Historical Data

It is possible to import historical data for metrics that have “day”, “week”, “days_28”, “month” parameters available. We haven’t found a way to get data for “lifetime” metrics.

In order to restore history you need to make a POST call:


Config is the name of needed extractor configuration table in sys bucket.

Same call could be used for any other additional parameters by adding them to the body of the call.



When all tables are imported to the Storage, all you need is put data together in a way your customer prefers.

Take a look at the attached csv's for examples of configurations. This is an exhaustive list of metrics around posts and pages (and videos in particular) and should help you a long way.

Ĉ
Pavel Boiko,
Nov 30, 2016, 11:04 AM
ċ
sys.c-ex-facebook.insightsPages_pivoted.csv
(1k)
Pavel Boiko,
Nov 30, 2016, 11:04 AM
ċ
sys.c-ex-facebook.insightsPost_pivoted.csv
(4k)
Pavel Boiko,
Nov 30, 2016, 11:04 AM
ċ
sys.c-ex-facebook.insightsPosts.csv
(1k)
Pavel Boiko,
Nov 30, 2016, 11:04 AM
Comments