的facebook Uncaught OAuthException: An active access token must be used to query information about the current userFacebook的OAuthException:活動的訪問令牌必須用於查詢當前用戶的信息
可能的複製,但我沒有得到妥善的解決方案。
我使用facebook sdk和codeigniter它工作正常。但有時會拋出異常OAuthException:必須使用活動訪問令牌來查詢有關當前用戶的信息。
這裏是控制器的代碼文件
$config = array(
'appId' => 'XXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX',
'fileUpload' => true,
);
$this->load->library('facebook/Facebook', $config);
$fbme = null;
$user = $this->facebook->getUser();
if ($user) {
try {
$fbme = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
//if user is logged in and session is valid.
if ($fbme){
//do some stuff...
//redirecting to user home page (my site's)
}
鑑於文件中,我使用的js SDK。代碼視圖文件是
<div id="fb-root"></div>
<script type="text/javascript">
var button2;
window.fbAsyncInit = function() {
FB.init({ appId: 'XXXXXXXX',
status: true,
cookie: true,
xfbml: true,
oauth: true});
function updateButton(response) {
button1 = document.getElementById('fb-login'); //login button
button2 = document.getElementById('fb-logout'); //logout button
if (response.authResponse) {
//user is already logged in and connected
button2.onclick = function() {
FB.logout(function(response) {});
};
} else {
//user is not connected to your app or logged out
button1.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'email,user_birthday,user_about_me,user_likes,user_interests,user_education_history,user_work_history'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
問題:
有時它拋出「OAuthException:一個積極的訪問令牌必須用於查詢當前用戶的信息」到錯誤日誌文件。
案例:用戶登錄Facebook和已驗證我的應用程序 如果用戶登錄Facebook和驗證我的應用程序,並試圖在我的網站上登錄, 而將用戶重定向到我的網站(PHP sdk在這種情況下不起作用),它正在加載視圖文件。在視圖文件中,我也在檢查用戶是否在Facebook上登錄。 (鑑於)如果用戶登錄它將重新加載頁面,相同的控制器腳本將運行,並將用戶重定向到用戶的主頁(php sdk在這種情況下工作)。
但第一次不起作用。不知道我犯了什麼錯誤。
另外,註銷按鈕(在視圖文件中)有時也不起作用。手段點擊它不會從Facebook註銷用戶。 (這隻發生在我的一個同事的瀏覽器中,她在windows 7中使用chrome)
FYI:該signed_request不是「無效」 - 但SDK會嘗試交換它裏面的'code'值當你每次訪問令牌發出新的請求,導致最近的更改後出現錯誤(2012年12月6日) – CBroe
這個問題解決了嗎? – siniradam
這也解決了我的問題。太好了! – Jeemusu