Created
October 31, 2018 17:44
-
-
Save xeoncross/5084d8937b7fd9f7b1fdfa09444f8d56 to your computer and use it in GitHub Desktop.
Example of accessing all facebook ad accounts for a given user
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
var main_page_id = "1235324234324" | |
var page_url = "https://www.facebook.com/name-here-1235324234324"; | |
fb.api('/oauth/access_token', { | |
client_id: config.facebook_api_key, | |
client_secret: config.facebook_api_secret, | |
redirect_uri: 'https://localhost:4430/auth/callback', | |
code: req.query.code // FYI, we're in an express.js handler | |
}, function(res_accesstoken) { | |
if (!res_accesstoken || res_accesstoken.error) { | |
console.log(!res_accesstoken ? 'error occurred' : res_accesstoken.error); | |
return; | |
} | |
var accessToken = res_accesstoken.access_token; | |
fb.api('/me/adaccounts', { | |
access_token: accessToken | |
}, function(res_adaccounts) { | |
console.log(res_adaccounts); | |
const adsSdk = require('facebook-nodejs-business-sdk'); | |
const api = adsSdk.FacebookAdsApi.init(accessToken); | |
api.setDebug(true); | |
const AdAccount = adsSdk.AdAccount; | |
const account = new AdAccount(res_adaccounts.data[0].id); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment