[英]Exchange short-lived access token for long-lived, not working
I am trying to exchange a short-lived user access token for a ling-lived, but getting an an error (in all.js): 我正在尝试将一个短暂的用户访问令牌交换为一个有效期,但是却出现错误(在all.js中):
ReferenceError: invalid assignment left-hand side ReferenceError:左侧的赋值无效
...TZCOZCkuZBxZAzVUSokiOJbXZAHhESJvuA97qXTpVbVj3P7AZDZD&expires=512326 ... TZCOZCkuZBxZAzVUSokiOJbXZAHhESJvuA97qXTpVbVj3P7AZDZD&期满= 512326
response.error.message: unknown error response.error.message:未知错误
Code: 码:
window.fbAsyncInit = function () {
FB.init({
appId: 'xxx', // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
oauth: true
});
FB.login(function (response) {
if (response) {
var accessToken = response.authResponse.accessToken;
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var accessToken = response.authResponse.accessToken;
var OauthParams = {};
OauthParams['client_id'] = 'xxx';
OauthParams['client_secret'] = 'xxx';
OauthParams['grant_type'] = 'fb_exchange_token';
OauthParams['fb_exchange_token'] = accessToken;
OauthParams['response_type'] = 'token';
console.log(accessToken);
FB.api('/oauth/access_token', 'post', OauthParams, function(response) {
if (!response || response.error) {
console.log(response.error.message);
}
else {
console.log(response.accesstoken);
}
});
}
});
};
}, { scope: 'manage_pages' });
};
}
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
Anyone has an idea? 有人有主意吗?
Thanks, /M 谢谢,/ M
according to scenario 4 of the documentation you have to send a GET
request to 根据文档的场景4,您必须将GET
请求发送至
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
maybe the problem is that you are using POST
request, but I am not sure 也许问题是您使用的是POST
请求,但我不确定
PS I wouldn't recommend to use APP_SECRET on client side PS我不建议在客户端使用APP_SECRET
I had a similar issue running tests from a FB Javascript SDK client. 我从FB Javascript SDK客户端运行测试时遇到类似的问题。 The problem on my end was that SDK was tripping handling the access_token in fb_exchange_token
. 我的问题是,SDK在处理fb_exchange_token
的access_token时fb_exchange_token
。 Changing just last three characters in this access token string made the error go away. 仅更改此访问令牌字符串中的最后三个字符即可使错误消失。 Of course, this doesn't help solving the problem, but at least this is where the issue was in my case. 当然,这无助于解决问题,但至少在我看来这就是问题所在。
Since these calls must be made from a server anyway, I am not going to proceed troubleshooting this further. 由于无论如何都必须从服务器发出这些调用,因此我将不进行进一步的故障排除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.