未捕获的OAuthException - 如何捕获此错误?

问题描述:

我有以下错误。我该如何捕捉这个错误?未捕获的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,但此心不是工作,所以我应该怎么做?

非常感谢您的帮助。

不要拧你的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 
}