Created
May 8, 2019 14:30
-
-
Save olegkalyta/e9ec2e275739e7cc939f7e7dc5c60dba to your computer and use it in GitHub Desktop.
FB Marketing API Question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const bizSdk = require('facebook-nodejs-business-sdk') | |
const accessToken = 'xxx' | |
const accountId = 'act_xxx' | |
const AdAccount = bizSdk.AdAccount | |
const Campaign = bizSdk.Campaign | |
const AdSet = bizSdk.AdSet | |
module.exports = () => { | |
const FacebookAdsApi = bizSdk.FacebookAdsApi.init(accessToken) | |
const account = new AdAccount(accountId) | |
const adSetFields = Object.values(AdSet.Fields) | |
return account | |
.read([AdAccount.Fields.name]) | |
.then(account => { | |
return account.getCampaigns([Campaign.Fields.name], { limit: 1 }) | |
}) | |
.then(result => { | |
const campain = result[0] | |
console.log(campain) | |
return campain.getAdSets(adSetFields).then(console.log) // The ad account and app id must be whitelisted | |
}) | |
.catch(err => { | |
console.error('+++', err.message) | |
return Promise.resolve('stop') | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment