facebook-nodejs-business-sdk icon indicating copy to clipboard operation
facebook-nodejs-business-sdk copied to clipboard

No way to override access_token

Open joshwreford opened this issue 3 years ago • 6 comments

Because the access_token is set when you first init the api e.g. const api = adsSdk.FacebookAdsApi.init(accessToken); it means that you are unable to switch it if required.

For example, I'm currently using a marketing access_token to get my parent business and to then get all facebook pages associated with that parent business manager. I can do this by running the method... parentBusinessManager.getClientPages();

I would then like to get all the instagram accounts associated with each of those Facebook pages. But if I try to do the following: page.getInstagramAccounts(['username']) It will throw an error saying that I need to use a "Page access token".

This is frustrating because the other access_token works for everything else. I actually get the page access_token back when I request the client pages, but there's no way to use it with the SDK at that point.

For example, I was hoping I could just override the access_tokenby passing it into the params like so:

this.page.getInstagramAccounts(
      ['username'],
      { access_token: accessToken },
    );

But, if you look at the code below in api.js, the access_token is overwritten on the params before the params object is used. https://github.com/facebook/facebook-nodejs-business-sdk/blob/4d52015eb512d9900bda7a93933e1b121b48915f/src/api.js#L77

It would be nice if the call() function checked whether you've passed a new access_token in the params argument, and if so, used it. Otherwise, it could fallback to using this.access_token. This seems like it would be a simple, yet powerful change that would allow a lot more flexibility with the SDK.

joshwreford avatar Mar 29 '21 14:03 joshwreford

I agree, if no access_token is present in a requests params, then the init access token should be a fallback.

In the case of App Access Tokens, you are able to pass off the token creation to the graph api like so: curl -i -X GET "https://graph.facebook.com/{api-endpoint}&access_token={your-app_id}|{your-app_secret}"

deanifrog avatar Jul 30 '21 05:07 deanifrog

@joshwreford I would love to pick this up, can you assign this to me?

adxy avatar Sep 22 '21 21:09 adxy

@joshwreford I would love to pick this up, can you assign this to me?

I don't have permissions to assign it I'm afraid

joshwreford avatar Sep 27 '21 10:09 joshwreford

Any updates on this? I'm having a similar problem. I'm working with multiple access tokens from multiple users and I am having problem with concurrent operations

brantian avatar Nov 03 '21 16:11 brantian

Hi, any update on this ?

alokpaidalwar avatar Jan 07 '22 12:01 alokpaidalwar

@joshwreford I'm fairly new this api but have you tried something like this?

const old = api.accessToken
api.accessToken = 'your-page-token'
// make call to get ig pages
// then reset
api.accessToken = old

michaelgainyo avatar Jan 20 '22 06:01 michaelgainyo