Lee*_*Tee 4 php api error-handling facebook-graph-api facebook-oauth
我有以下错误.我怎么能抓到这个错误?
致命错误:未捕获OAuthException:验证访问令牌时出错:用户638720122未授权应用程序207445576002891.在第1039行的/var/www/clients/client1/web12/web/socialmediaping/fblibrary/base_facebook.php中引发
我有以下代码片段,我相信我会尝试管理错误.
// 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;
}
Run Code Online (Sandbox Code Playgroud)
如果$ facebookAuth == FALSE,我将用户重定向到facebook以进行身份验证,但这不起作用,那么我应该怎么做?
非常感谢您的帮助.
不要搞砸你的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
}
Run Code Online (Sandbox Code Playgroud)