2011-12-13 79 views
4

我有以下錯誤。我該如何捕捉這個錯誤?未捕獲的OAuthException - 如何捕獲此錯誤?

Fatal error: Uncaught OAuthException: Error validating access token: User 638720122 has not authorized application 207445576002891. thrown in /var/www/clients/client1/web12/web/socialmediaping/fblibrary/base_facebook.php on line 1039

我有下面的代碼片段,我相信我會嘗試管理錯誤。

// Attempt to query the graph: 
$graph_url = "https://graph.facebook.com/me?" 
    . "access_token=" . $access_token; 
$response = curl_get_file_contents($graph_url); 
$decoded_response = json_decode($response); 

//Check for errors 
if ($decoded_response->error) { 
    $facebookAuth = FALSE; 
} 

再往下我將用戶重定向到Facebook來authoise如果$ facebookAuth == false,但此心不是工作,所以我應該怎麼做?

非常感謝您的幫助。

回答

7

不要擰你的base_facebook.php!只需在圖形調用周圍使用try/catch塊:

try { 

    // check if facebook can get user 
    $facebookUser = $facebook->getUser(); 
    $facebookUser = $facebook->api('me?fields=id,first_name,last_name'); 

} catch (Exception $e) { 
    // user is not logged in 
} 
相關問題