当用户授权应用程序但是PHP中的秘密错误时,我如何发现案例?

时间:2012-05-04 19:23:54

标签: facebook authentication facebook-graph-api

在我的应用程序中,我需要处理所有各种情况。我对标准情况没有任何问题,我遇到了边缘情况的问题,例如

  • app secret已输入错误
  • 用户取消了我的应用

这是我的代码

//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()块中,你应该这样做,但我不知道要检查什么代码。

任何人都可以提供帮助吗?

0 个答案:

没有答案