dongnuo6310 2016-08-03 23:13
浏览 389

如何处理在Facebook中取消授权您的应用程序所产生的错误

I am trying to figure out how to handle error created when a user de-authorizes my Facebook app. I'm using larval 5 and this is the current error I'm getting:

Error validating access token: The user has not authorized application

the access_token is being stored in current session. Is there a way i can use a try and catch statement or any clever solution, so that when I get an access_token that doesn't validate I can still continue with the rest of the code.

below is the code i'm using, it world great infill app gets reauthorized:

$token = Session::get('fb_user_access_token');

    $permissionsToRequest = ([
        'public_profile',
        'publish_actions'
    ]);

    $login_link_for_public_actions = $fb->getLoginUrl($permissionsToRequest, 'http://pms.dev:8000/facebook/publicactions/callback');

    if (isset($token)) {

        $fb->setDefaultAccessToken($token);
        try {
        // Returns a `Facebook\FacebookResponse` object
        $response = $fb->get('/me?fields=permissions');
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
        }

        // Returns a `Facebook\GraphNodes\GraphUser` collection
        $facebookuser = $response->getGraphUser();
        $ty= json_decode($facebookuser);

        $permissions = $facebookuser['permissions'];

        $checked = '';
        foreach ($permissions as $p) {
            if ($p['permission'] == 'publish_actions' && $p['status'] == 'granted' ) {
            $checked = 'checked';
            }
        }
    } else {
        $checked = null;
    }

I narrowed it down to the error coming somewhere from the try catch statement:

   try {
        // Returns a `Facebook\FacebookResponse` object
        $response = $fb->get('/me?fields=permissions');
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
        }

i'm getting this error in my view : FacebookResponseException in FacebookResponseException.php line 89:

I tried dd() different values inside the catch statements but nothing changes. I think i'm grabbing the wrong exeption , not sure what else to do?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度