lkenneth
lkenneth

Reputation: 131

How to set the access token with the Javascript SDK?

I am searching for something similar to what Facebook::setAccessToken($access_token) does in the PHP SDK ; that is, set the access token used for subsequent requests (having retrieved it by other means).

In the Javascript one, I can only find the getter (FB.getAccessToken). I imagine this has been made on purpose to avoid using the access token client-side, but what are the risks if only the user related to the access token can see it ?

I could embed it as a parameter for each query, but this is impossible for XFBML as far as I know.

Any idea ?

Upvotes: 7

Views: 3545

Answers (1)

lkenneth
lkenneth

Reputation: 131

There is nothing built-in in the SDK.

If you really needed it, you could hack it this way:

FB.provide('', {
  'setAccessToken': function(a) {
    this._authResponse = { 'accessToken': a };
  }
});
// Usage
FB.setAccessToken('my_access_token');

But if you do this, Facebook will log to their server that you use a "deprecated" function of their SDK and send you a warning message. Better pass it to the requests directly (this is what I ended up to).

That does not work for XFBML though (you will have to issue FQL queries yourself and populate your own markup).

Upvotes: 1

Related Questions