Abhishek Agarwal
Abhishek Agarwal

Reputation: 724

Initializing FB session on client using javascript sdk and long lived token

I am a bit confused about the implementation of access token in FB graph api.

According to the docs I can pass the access token to client and initialize the session using this access token

https://developers.facebook.com/docs/facebook-login/access-tokens

So if I have a long lived access token on server side and pass it to the javascript sdk on client side...is it possible to make graph api calls from client? How?

Upvotes: 1

Views: 524

Answers (1)

Francisco Gonzalez Rull
Francisco Gonzalez Rull

Reputation: 1495

Facebooks's JS SDK .api() method always accepts a parameter called access_token, that can be a User access_token or a Page access_token depending on the calls you are making. See the following example using Angular's SDK:

Get a this.fb.api(pageId + '?fields=picture,fan_count,name', 'get', { 'access_token': <USER_ACCESS_TOKEN> })

Where <USER_ACCESS_TOKEN> is given to you by your backend without exposing your API secret ever. So, in summary.

See Generating Long-Lived User Tokens from Server-Side Long-Lived Tokens for more info.

Upvotes: 1

Related Questions