facebook-nodejs-business-sdk
Version:
SDK for the Facebook Ads API in Javascript and Node.js
63 lines (58 loc) • 1.86 kB
JavaScript
/**
* 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 bizSdk = require('facebook-nodejs-business-sdk');
const process = require('process');
const User = bizSdk.User;
const Page = bizSdk.Page;
let app_id = '1224202007596125';
let access_token = 'EAARZAZA73LzF0BACZADSZCYwMsLHUTwAAYKm5Tciz5GZCGM8ZAtqoM12q8ybFt6dpElSqbUuXm77dGmZAeK6r1wygAQZCslDqpsVQY6RQA3WhLirP8BcgoKoCTvlyKzkx6xGPZCcRiDXUleDqSbnAQBd5k0ZBhuLf1AB2VsIS5OlYDoTQlOoRuVpmZAiJY9O6d688sZD';
let app_secret = '709348c9665c33a4f988ff3950098131';
let user_id_for_page = '10150023100686117';
const api = bizSdk.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;
void async function() {
try {
// _DOC oncall [business_api]
// _DOC open [PAGE_CREATE]
// _DOC vars [access_token]
// _DOC vars [user_id]
fields = [
];
params = {
'name' : 'My Personal Blog',
'category_enum' : 'PERSONAL_BLOG',
'about' : 'Just trying some things with the API',
'picture' : 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
'cover_photo' : {'url':'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
'location' : {'city':'Seattle', 'country':'US', 'state':'WA'},
'address' : '1101 Dexter Ave N',
};
let page = await (new User(user_id_for_page)).createAccount(
fields,
params
);
// _DOC close [PAGE_CREATE]
}
catch(error) {
console.log(error);
process.exit(1);
}
}();