如何使用Javascript SDK设置访问令牌? [英] How to set the access token with the Javascript SDK?
问题描述
我正在寻找类似于Facebook::setAccessToken($access_token)
在PHP 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).
在Java语言中,我只能找到吸气剂(FB.getAccessToken
).我想这是故意避免使用客户端的访问令牌,但是如果仅与访问令牌相关的用户可以看到它,会有什么风险?
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 ?
我可以将其作为每个查询的参数嵌入,但是据我所知,这对于XFBML是不可能的.
I could embed it as a parameter for each query, but this is impossible for XFBML as far as I know.
有什么主意吗?
推荐答案
SDK中没有内置的东西.
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');
但是,如果您这样做,Facebook将登录到他们使用其SDK的已弃用"功能的服务器,并向您发送警告消息. 最好直接将其传递给请求(这就是我最终要解决的问题).
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).
但这不适用于XFBML(您必须自己发出FQL查询并填充您自己的标记).
That does not work for XFBML though (you will have to issue FQL queries yourself and populate your own markup).
这篇关于如何使用Javascript SDK设置访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!