Reputation: 305
I would like to connect to the Facebook Ads Insights API with google scripts in order to generate and update a google sheet containing my ads key performance indicators.
I have read Facebook's documentation but I'm a bit lost, for example In the documentation's website, I can see that I am supposed to follow this syntax to get a campaign's impressions
GET <AD_OBJECT>/insights?fields=impressions
but I'm not quite sure where that would fit in a cURL get query, should it look like this ?
https://graph.facebook.com/v2.5/CAMPAIN_ID/insights?fields=impressions%?access_token=TOKEN
I have tried to build the following google script but I'm not sure it's getting anywhere, any help ?
var myClientID = '';
var myClientSecret = '';
var myAccessToken = 'MY_TOKEN';
var graphURL = 'https://graph.facebook.com/v2.5/';
function getPageLikes(campaign_id) {
var searchParams = '?fields=impressions%2Cunique_clicks%2Creach';
var campaignID = MY_CAMPAIGN_ID;
var fullURL = graphURL + campaignID + '/insights/' + searchParams + '&access_token=' + myAccessToken;
var fetchResult = UrlFetchApp.fetch(fullURL);
var campaign = JSON.parse(fetchResult);
var likes = campaign.data[0];
return campaign_data;
}
Thank you
Upvotes: 0
Views: 9780
Reputation: 3337
Yes. If you like CURL, you should play with https://developers.facebook.com/tools/explorer/
Then you can formulate something like: https://graph.facebook.com/v2.9/[campaign_id]/insights?fields=impressions%2Creach&access_token=[token]
But if you want an easier life, I would recommend you to use one of the SDK. There is one for
And we also have a tool to guide you generate code in the Getting Started session in https://developers.facebook.com/apps/[app_id]/marketing-api/ Basically you can pick metrics and the wizard will generate a working code for you. (It is only generating Java code for now)
Also if you don't really wants to code, you may try the new product we just released called Facebook Ads Manager for Excel. It allows you to download Insights data into Excel directly. More info:
https://www.facebook.com/business/m/facebook-ads-manager-for-excel
Upvotes: 2