0

我在测试时遇到了这个问题。

在我的应用程序中,用户单击一个链接,该链接使他们登录并授予我的应用程序权限。

问题是我成功完成一次后,我不能再轻易地再做一次。我在 Facebook 对象中对用户的检查返回存在用户,但访问令牌无效。我收到以下错误:

Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/kleelof/public_html/projects/tutor_chapter/facebook_login/facebook/base_facebook.php on line 1028

这是我的一些代码:

The variable $fb is set to the Facebook object before the following code is executed. .

     $user = $fb->getUser();    
     if ($user)
    {
        // get coupon code
        $coupon_code = file_get_contents(CODE_URL . "/facebookcoupon.php?email=$user_email");

        // check that the user has given the app permission to post on their wall.
        //try
        //{
            $permissions = $FB->api("/me/permissions");

            if (array_key_exists('publish_stream', $permissions['data'][0])) 
            {
                // build attachment
                $attachment = array(
                                    'name' => $site_name,
                                    'link' => urlencode(BASE_URL . str_replace('%code%', $coupon_code, $claim_link)),
                                    'picture' => $image_link,
                                    'description' => str_replace('%code%', $coupon_code, $description),
                                    'access_token' => $FB->getAccessToken()
                                    );

                $FB->api('/me/feed/', 'post', $attachment);

                $exit_to .= "?ce=The coupon has been posted on your Facebook timeline";
            }
            else
            {
                $exit_to .= "?ce=Unable to post the coupon";
            }
        //}catch (Exception $e) 
        //{
            /*$exit_to = $FB->getLoginUrl(  
                                    array(
                                            'scope' => FB_LOGIN_SCOPE
                                            )
                                    );
        }*/
    }
    else
    {//echo("no user");
        $exit_to = $FB->getLoginUrl(    
                                    array(
                                            'scope' => FB_LOGIN_SCOPE
                                            )
                                    );
    }

你可以看到我试图捕捉我上面提到的错误并将它们发送回登录,但它只是陷入到去 FB 并被返回的循环中。

有人在逻辑中看到不正确的东西吗?

有没有更好的方法来处理异常?也许我可以做些什么来使 $user 为空。

保重,李

4

0 回答 0