Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 测试期间Facebook访问令牌_Php_Facebook - Fatal编程技术网

Php 测试期间Facebook访问令牌

Php 测试期间Facebook访问令牌,php,facebook,Php,Facebook,我在测试时遇到了这个问题 在我的应用程序中,用户单击一个链接,该链接将引导他们登录并授予我的应用程序权限 问题是,在我成功地做了一次之后,我不能轻易地再做一次。我对Facebook对象中用户的检查返回有一个用户,但访问令牌无效。我得到以下错误: Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown i

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

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

问题是,在我成功地做了一次之后,我不能轻易地再做一次。我对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为空

保重,,
lee

在你的代码中,我找不到你在哪里为$user设置了值,你确定你没有忘记这么做吗?我忘了提到它是来自Facebook的用户对象。我已经更新了我的帖子,将任务显示给$user-lee您还可以检查$user持有的值吗?在授予权限之后。我现在实际上无法访问它。然而,这是几乎每个FB教程中使用的技术。我认为问题在于Facebook对象正在缓存这些值。我可能正在寻找清除该对象的方法。可能会出现各种各样的问题,例如,如果用户的浏览器中不允许使用第三方cookie,并且用户正在从facebook选项卡访问您的页面,facebookSDK将无法保存用户ID,并且您的$user将始终为0