Akk
Akk

Reputation: 406

FB graph api returns short lived token instead of long lived token

I'm trying to get long lived token for pages which doesn't expire. To do this, I first get the long lived user access token. Once my app has that, it makes a call to get the page token using the following code:

var URL = "/PAGE_ID/?fields=access_token=LONG_USER_ACCESS_TOKEN";
FB.api(URL, function(response) {
}

The token returned is though short lived. However, if I use the same URL and call it using the FB Graph API Explorer, the token I receive is long token.

I'm not sure why the same URL will generate a short token when I call is using FB.api(){} vs. a long token when I test it using the FB Graph API Explorer.

Upvotes: 0

Views: 419

Answers (1)

C3roe
C3roe

Reputation: 96363

var URL = "/PAGE_ID/?fields=access_token=LONG_USER_ACCESS_TOKEN";

You are not passing an access token at all here. What you are doing, is passing one parameter named fields with the value access_token=LONG_USER_ACCESS_TOKEN

You want to pass one parameter named fields with the value access_token, and one parameter named access_token wit the value LONG_USER_ACCESS_TOKEN - so that URL of course has to look like this:

var URL = "/PAGE_ID/?fields=access_token&access_token=LONG_USER_ACCESS_TOKEN";

Upvotes: 1

Related Questions