我正在尝试获取登录的 facebook 用户的 access_token。
我得到这样的东西.. url 后跟代码我正在检索代码..
指南中说用它交换access_token ...
https://graph.facebook.com/oauth/access_token ? client_id=XXXXXXXXXXXXXX& redirect_uri= http://www.my-site.com/& client_secret=XXXXXXXXXXXXXXXXXXXXX& code=2.hJFWoMlLf3tLOSos_qNCBg__.3600.1279836000-10000100XXXXXXX|kGwPB4y5K_-ijD9_1CfjSpT-oaY..
我如何使用 FB.api 或 jquery 或 javascript 将其交换为 access_token..
当我将此 URL 插入地址栏时..我能够看到 access_token..
如果有人能告诉我如何使用 javascript 或 jquery 检索 access_token,我将不胜感激。
谢谢。
最佳答案
根据 Facebook 和我个人使用 api 的经验,FB.getSession()
函数已被弃用,如果调用它应该抛出异常。
来自 Facebook :
The FB.getAuthResponse method is a replacement for the FB.getSession method which was deprecated after the migration to OAuth 2.0.
相反,您应该使用 getLoginStatus 回调 -
FB.getLoginStatus(function(response) {
var token = response.authResponse.accessToken;
});
//Example structure of response object
var eg =
{
status: 'connected',
authResponse: {
accessToken: '...',
expiresIn:'...',
signedRequest:'...',
userID:'...'
}
};
来源:http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
关于facebook - 如何检索 facebook oauth 2.0 access_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3313111/