How to set the access token with the Javascript SDK?

∥☆過路亽.° 提交于 2019-12-22 04:41:17

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/11393012/how-to-set-the-access-token-with-the-javascript-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!