GithubHelp home page GithubHelp logo

Comments (6)

zanyaziz avatar zanyaziz commented on April 24, 2024

Try this example below. Note that only the fields you specified in the read fields param are the ones that will be populated in the $account response.

const adsSdk = require('facebook-nodejs-ads-sdk');
const accessToken = '<ACCESS_TOKEN>';
const accountId = 'act_<ACCOUNT_ID>';
const FacebookAdsApi = adsSdk.FacebookAdsApi.init(accessToken);
FacebookAdsApi.setDebug(true);
const AdAccount = require('facebook-nodejs-ads-sdk').AdAccount;
const account = new AdAccount(accountId);

console.log(account.id) // fields can be accessed as properties
account
.read([AdAccount.Fields.name, AdAccount.Fields.age])
.then((account) => {
console.log(account);
})
.catch((error) => {
console.log('An error occurred');
});

from facebook-nodejs-business-sdk.

jeffreydinh avatar jeffreydinh commented on April 24, 2024

I'm getting this error when I ran the code you provided:

An error occurred: FacebookRequestError: (#100) Tried accessing nonexisting field (age) on node type (Application)

It seems to not work when I add more than one field to the array. I tried with these fields as well:

const adsSdk = require('facebook-nodejs-ads-sdk');
const FacebookAdsApi = adsSdk.FacebookAdsApi.init(accessToken);
FacebookAdsApi.setDebug(true);
const AdAccount = require('facebook-nodejs-ads-sdk').AdAccount;
const account = new AdAccount(accountId);

console.log(account.id) // fields can be accessed as properties
account
.read([AdAccount.Fields.name, AdAccount.Fields.balances])
.then((account) => {
console.log(account: ${account.account_id});
})
.catch((error) => {
console.log(An error occurred: ${error});
});

And it gives a different error than the age field:

An error occurred: FacebookRequestError: Syntax error "Expected name." at character 5: name,

from facebook-nodejs-business-sdk.

zanyaziz avatar zanyaziz commented on April 24, 2024

Here's how you can do what you're trying to achieve.

const adsSdk = require('facebook-nodejs-ads-sdk');
const accessToken = '<Access_Token>';
const accountId = 'act_<Account_ID>';
const FacebookAdsApi = adsSdk.FacebookAdsApi.init(accessToken);
FacebookAdsApi.setDebug(true);
const AdAccount = require('facebook-nodejs-ads-sdk').AdAccount;
const account = new AdAccount(accountId);

account
.read([AdAccount.Fields.name, AdAccount.Fields.age])
.then((account) => {
console.log(account.name);
console.log(account.age);
})
.catch((error) => {
console.log('An error occurred');
console.lof(error);
});

account
.read([AdAccount.Fields.age])
.then((account) => {
console.log(account.age);
})
.catch((error) => {
console.log('An error occurred');
console.log(error);
});

from facebook-nodejs-business-sdk.

zanyaziz avatar zanyaziz commented on April 24, 2024

Did that resolve your issue?

from facebook-nodejs-business-sdk.

jeffreydinh avatar jeffreydinh commented on April 24, 2024

This did not resolve my issue. I'm still getting the same errors

from facebook-nodejs-business-sdk.

zanyaziz avatar zanyaziz commented on April 24, 2024

I looked into the issue. It seems like this may be an intermittent issue with the APIs and not the SDK. Can you file a bug at https://developers.facebook.com/bugs/

from facebook-nodejs-business-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.