在我的应用程序中,我需要处理所有各种情况。我对标准情况没有任何问题,例如,我对边缘情况有一些问题
- 应用密码输入错误
- 用户取消了我的应用程序的授权
这是我的代码
//I have already checked that the app id is valid
require AI1EC_LIB_PATH . '/facebook-php-sdk/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => $plugin_settings['facebook-app-id'],
'secret' => $plugin_settings['facebook-app-secret'],
));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ( $user ) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api( '/me' );
} catch ( FacebookApiException $e ) {
error_log( json_encode( $e->getResult() ) );
$user = NULL;
}
}
// Login or logout url will be needed depending on current user state.
if ( $user ) {
$logout_url = $facebook->getLogoutUrl();
echo "OK!";
} else {
$params = array(
'scope' => 'user_events, friends_events',
);
$login_url = $facebook->getLoginUrl( $params );
$args = array(
'login_url' => $login_url,
);
$ai1ec_view_helper->display_admin( 'plugins/facebook/user_login.php', $args );
}
我应该把特定错误的处理放在哪里?我很想向用户显示一个很好的消息,比如“出了点问题,检查你是否正确输入了你的应用程序密码”或“你已经取消了你的应用程序的授权”。也许你应该在 catch() 块中这样做,但我不知道要检查哪些代码。
任何人都可以帮忙吗?