2012-03-08 80 views
0

我有一些奇怪的問題構建Facebook的iframe應用程序。該應用程序似乎陷入了無限循環轉到應用程序頁面。Facebook的PHP SDK 3.1.1「錯誤驗證訪問令牌」後去轉到應用頁

用戶在轉到應用程序頁面授權應用程序並返回到應用程序後,/ me api調用將引發「驗證訪問令牌的錯誤」異常。我檢查並且在簽名請求中有一個有效的訪問令牌(使用facebook訪問令牌調試工具進行測試)。我試圖用setAccessToken()方法設置失敗。 getUser()方法成功返回用戶標識,但它仍掛在/ me api調用上。

這不會發生在每個瀏覽器中,我只是在Chrome中看到它,有時並不清晰。我使用P3P標題在IE中修復了它。它在Firefox中正常工作。

我幾乎卡住了,我頭髮拔出,所以任何想法都歡迎。非常感謝。

完整的錯誤消息:「驗證訪問令牌的錯誤:您無法訪問該應用程序,直到您登錄到www.facebook.com並按照給出的說明進行操作。」

下面的代碼。

$this->_facebook = new Facebook(
    array(
     'appId' => $this->_config['appId'], 
     'secret' => $this->_config['secret'], 
     'cookie' => true, 
     'fileUpload' => true 
    ) 
); 

$this->_signedRequest = $this->_facebook->getSignedRequest(); 

// Doing something with signed request, not FB related 

$this->_userId = $this->_facebook->getUser(); 

if($this->_userId) { 
    try{ 
     // At this line the "Error validating access token" error shows up 
     $this->_user = $this->_facebook->api('/me'); 

     // Some more irrelevant code here 

    } catch (Exception $e){ 
     $this->_facebook->destroySession(); 
     $this->_facebookLogin(false); 
    } 
} else { 
    $this->_facebook->destroySession(); 
    $this->_facebookLogin(false); 
} 

// The _facebookLogin method 
public function _facebookLogin($perms = 'email,user_birthday,publish_stream,video_upload'){ 
    $data = array(
     'fbconnect' => 0, 
     'redirect_uri' => 'aredirecturl.com' 
    ); 

    if(!empty($perms)) { 
     $data['scope'] = $perms; 
    } 
    echo '<script type="text/javascript">window.top.location.href = "'.$this->_facebook->getLoginUrl($data).'";</script>'; 
    exit; 
} 
+0

你可以把你的完整代碼(例如在這個代碼中'公共函數_facebookLogin'是錯誤的 – 2012-03-09 20:38:34

+0

我面臨同樣的問題,鉻也是如此。@Cazacu弗拉德如果你找到解決方案,請在這裏發帖謝謝 – 2012-09-09 00:24:57

回答

0

編輯這部分

// At this line the "Error validating access token" error shows up 
$this->_user = $this->_facebook->api('/me'); 

這個

// At this line the "Error validating access token" error shows up 
$this->_user = $this->facebook->api('/me','GET'); 
+0

感謝您的答案,但是沒有做到這一點。就我所見,GET是圖形調用的默認設置,所以它已經在使用它了。 – 2012-03-09 11:13:01

0

什麼手工摧毀你的會議?你調試過這些參數嗎?

unset($_SESSION['fb_'.$YOUR_API_KEY.'_code']); 
unset($_SESSION['fb_'.$YOUR_API_KEY.'_access_token']); 
unset($_SESSION['fb_'.$YOUR_API_KEY.'_user_id']); 
unset($_SESSION['fb_'.$YOUR_API_KEY.'_state']); 

我幾乎使用相同的代碼如你,但我不使用fileUpload和cookie的參數。

相關問題