Skip to content

Instantly share code, notes, and snippets.

@mitchellporter
Created October 17, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellporter/1c39bfcd523eb44498b37d6a66ae1a9b to your computer and use it in GitHub Desktop.
Save mitchellporter/1c39bfcd523eb44498b37d6a66ae1a9b to your computer and use it in GitHub Desktop.
Fetching ad account campaigns with Facebook Business Node.js SDK
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
* @flow
*/
const adsSdk = require('facebook-nodejs-ads-sdk');
const AdAccount = adsSdk.AdAccount;
const Campaign = adsSdk.Campaign;
let access_token = '<ACCESS_TOKEN>';
let app_secret = '<APP_SECRET>';
let app_id = '<APP_ID>';
let id = '<ID>';
const api = adsSdk.FacebookAdsApi.init(access_token);
const showDebugingInfo = true; // Setting this to true shows more debugging info.
if (showDebugingInfo) {
api.setDebug(true);
}
const logApiCallResult = (apiCallName, data) => {
console.log(apiCallName);
if (showDebugingInfo) {
console.log('Data:' + JSON.stringify(data));
}
};
let fields, params;
fields = [
'name',
'objective',
];
params = {
'effective_status' : ['ACTIVE','PAUSED'],
};
let campaignss = (new AdAccount(id)).getCampaigns(
fields,
params
);
logApiCallResult('campaignss api call complete.', campaignss);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment