Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 246
lkenneth Avatar asked Jul 09 '12 10:07

lkenneth


People also ask

What are SDK tokens?

The Tokens SDK provides you with the fastest and easiest way to create tokens that represent any kind of asset on your network. This asset can be anything you want it to be - conceptual, physical, valuable or not.

What is auth token in JavaScript?

This token verifies your identity. It can authenticate who you are, and authorize various resources you have access to. If you by any chance don't know any of these keywords, be patient, I'll explain everything below. This will be a step by step tutorial of how to add token based authentication to an existing REST API.


1 Answers

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).

like image 87
lkenneth Avatar answered Oct 01 '22 20:10

lkenneth