我正在尝试将一个短暂的用户访问令牌交换为一个有效期,但是却出现错误(在all.js中):
ReferenceError:左侧的赋值无效
... TZCOZCkuZBxZAzVUSokiOJbXZAHhESJvuA97qXTpVbVj3P7AZDZD&expires = 512326
response.error.message:未知错误
码:
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));
有人有主意吗?
谢谢,
/米
最佳答案
根据documentation的方案4,您必须向
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
也许问题是您使用的是
GET
请求,但是我不确定附言我不建议在客户端使用APP_SECRET