Skip to content

Instantly share code, notes, and snippets.

@IronistM
Forked from chipoglesby/facebookads.gs
Last active April 10, 2018 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IronistM/0ed6c9e22f94f7048533 to your computer and use it in GitHub Desktop.
Save IronistM/0ed6c9e22f94f7048533 to your computer and use it in GitHub Desktop.
Pull Facebook Advertising Metrics into Google Sheets
var SPREADSHEET_URL = "";
function facebookSpend() {
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = ss.getSheetByName('facebook');
var values = [];
Utilities.sleep(1000);
var fullUrl = 'https://graph.facebook.com/v2.3/act_xxx/stats?access_token=xxx';
var fetchRequest = UrlFetchApp.fetch(fullUrl);
var results = JSON.parse(fetchRequest.getContentText());
Logger.log(results.spent/100);
values.push('spend',results.spent/100);
sheet.appendRow(values);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment