[英]Exchange short-lived access token for long-lived, not working
我正在嘗試將一個短暫的用戶訪問令牌交換為一個有效期,但是卻出現錯誤(在all.js中):
ReferenceError:左側的賦值無效
... TZCOZCkuZBxZAzVUSokiOJbXZAHhESJvuA97qXTpVbVj3P7AZDZD&期滿= 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));
有人有主意嗎?
謝謝,/ M
根據文檔的場景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
也許問題是您使用的是POST
請求,但我不確定
PS我不建議在客戶端使用APP_SECRET
我從FB Javascript SDK客戶端運行測試時遇到類似的問題。 我的問題是,SDK在處理fb_exchange_token
的access_token時fb_exchange_token
。 僅更改此訪問令牌字符串中的最后三個字符即可使錯誤消失。 當然,這無助於解決問題,但至少在我看來這就是問題所在。
由於無論如何都必須從服務器發出這些調用,因此我將不進行進一步的故障排除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.