-
Notifications
You must be signed in to change notification settings - Fork 8
Home
Getting insights out of Facebook can be a little tedious and the existing packages are a little complicated, so we wrote a package to save ourselves time. We use it all the time, so we thought we’d share.
We’ve not submitted to CRAN and have no immediate plans to do so. You’ll need to install via devtools and update likewise.
- You'll need to create a Facebook app; simple enough to do through Business Manager and with a developer account.
- You’ll need an app access token with ad rights - you can get one through the Facebook Graph Explorer .
- Apps are easy to create and you don't need to get it approved to use for this purpose.
- Switch to that app in Facebook Graph Explorer in the 'Application [?]' dropdown and click ‘Get Token’ then 'Get User Access Token'.
- You’ll need to make sure you personally have admin access to the app and at least advertiser access to the appropriate ad account.
- You'll also need a page access token to grab page insights and can use the same methods as above.
- You can use this same page access token to grab Instagram insights if the account is connected to the Facebook page through Business Manager and is a true Instagram business account.
- Only 30 days' Instagram data can be extracted through the API.
- You can allocate admin rights through Facebook Business Manager.
There’s also an option to extend the life of tokens here.
This is visible in ads manager in business manager and is always prefixed with ‘act_’, eg. act_12344321 .
This appears in several places - in business manager and also in the actual URL of the page itself.
This is confusing and may take some trial and error as there are several IDs discoverable. We found ours through the Graph Explorer.
The instructions in the package are now up to date and visible after loading the package through:
library(FBinsightsR)
by,
?fbins_summ
,
?fbins_ag
,
?fbins_page
or,
?fbins_insta
fbins_sum
has 6 arguments:
fbins_sum(start_date, until_date, report_level, time_increment, fb_access_token, fb_ad_account)
fbins_ag
has 5 arguments:
fbins_ag(start_date, until_date, report_level, fb_access_token, fb_ad_account)
fbins_page
has 5 arguments:
fbins_ag(start_date, until_date, period, page_access_token, page_account)
fbins_insta
has 5 arguments:
fbins_ag(start_date, until_date, period, page_access_token, insta_account)
... all functions will return a data frame with the latter two returning the date column in date format.
fbins_ag
can return A LOT of data given everything is dimensioned by age and gender, so the API may time out. You may have to perform several calls by shorter time periods to prevent this.
The initial feedback has been around access token confusion - we may look to automate some of this at some point in the future.