Facebook 查询在 PHP 中失败 - 访问令牌问题

发布于 2024-12-16 15:32:43 字数 2225 浏览 3 评论 0原文

我正在使用 Facebook iFrame 应用程序尝试 FQL。最近,当我尝试执行简单的 FQL 查询(例如获取用户朋友的数组)时,我刚刚开始遇到间歇性错误...我收到以下错误消息:

致命错误:未捕获异常:102:需要在 base_facebook.php 第 1039 行中抛出用户会话

似乎清除此消息的唯一方法是清除我的所有 cookie。简单地注销并重新登录 Facebook 并不能阻止它。令人沮丧的是,我无法根据需要重复错误,这使得很难追踪正在发生的事情,但从 base_facebook.php 上查看该行来看,它似乎是异常由于访问令牌不再有效而被抛出,

我该如何解释?即我如何检查访问令牌是否仍然有效,如果不是请求/设置一个新的?我正在使用最新的 Facebook PHP SDK v3 和 CodeIgniter 框架。

有一个类似的问题,但它与早期版本的 SDK 有关,因此不再有效。

编辑:尝试了其他一些事情...当索引页面检测到用户已登录时,它不会重定向到 oauth 链接(即 https://www.facebook.com/dialog/oauth?client_id-etc。)。作为测试,我尝试将该链接放置在页面上,尝试单击并强制进行新的身份验证。那也没用。我尝试将访问令牌设置为 null,然后获取一个新的。那里也没有运气。唯一的解决方法仍然是清除浏览器中的所有 cookie。

任何有关如何调试/解决方案等的信息/提示的链接,一如既往地非常感谢!

下面是代码的概要:

public function index()
{
    $this->load->library('facebook'); 

    // check if we can retrieve user id from facebook -    

    $user = $this->facebook->getUser();

    if (!$user) 

    { // if no user id there then redirect to Facebook login page 

         $this->loginByFacebook();   
    } 
    else // if we have id then we have a logged in FB user
    {                           

      $fb_uid = $user;
      $fb_usr = $this->facebook->api('/me');

      print_r($fb_usr); // This always works and outputs my FB info

     // HERE I PUT A LINK TO NEW PAGE WHICH IS CREATED WITH FUNCTION BELOW

}

function getFriendsList () {

    //echo "here";
    $this->load->library('facebook'); 
    //$access_token = $this->facebook->getaccessToken(); 
    $query = '
        SELECT first_name, last_name, name, uid,pic_square FROM user
        WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me() ) 
        ORDER BY name';


         // I have tried running the query by getting access token and supplying it and without and still have the same problem.

    //$FQL = array ( "method" => "fql.query", "query" => $query, "access_token" => $access_token);
        $FQL = array ( "method" => "fql.query", "query" => $query);

    $data = $this->facebook->api($FQL);     

    return $data;           

}

I'm playing around with FQL with a Facebook iFrame app. I have just started getting an intermittent error recently when I attempt a simple FQL query such as get an array of the user's friends... I get the following error message:

Fatal error: Uncaught Exception: 102: Requires user session thrown in base_facebook.php line 1039

The only thing that appears to clear this message is clearing all of my cookies. Simply logging out and back in to Facebook does not stop it. The frustrating thing is I that I am unable to repeat the error on demand which is making it hard to track down what is going on but from looking at that line on base_facebook.php it appears as though the exception was thrown because the access token is no longer valid

How do I account for this? i.e. How can I check whether the access token is still valid or not and if not request/set a new one? I'm using the latest Facebook PHP SDK v3 with CodeIgniter framework.

There was a similar question but it related to the earlier version of the SDK so no longer valid.

EDIT: Tried a few other things... As the index page detects that the user is logged in it doesn't redirect to the oauth link (i.e. https://www.facebook.com/dialog/oauth?client_id-etc.) . As a test I tried placing that link on the page anyway to try clicking and force new authentication. That didn't work either. I've tried setting access token to null and then getting a new one. Also no luck there. The only fix still is to clear all cookies in the browser.

Any links to info/tips on how to debug/solutions etc. greatly appreciated as always!

Here's an outline of the code:

public function index()
{
    $this->load->library('facebook'); 

    // check if we can retrieve user id from facebook -    

    $user = $this->facebook->getUser();

    if (!$user) 

    { // if no user id there then redirect to Facebook login page 

         $this->loginByFacebook();   
    } 
    else // if we have id then we have a logged in FB user
    {                           

      $fb_uid = $user;
      $fb_usr = $this->facebook->api('/me');

      print_r($fb_usr); // This always works and outputs my FB info

     // HERE I PUT A LINK TO NEW PAGE WHICH IS CREATED WITH FUNCTION BELOW

}

function getFriendsList () {

    //echo "here";
    $this->load->library('facebook'); 
    //$access_token = $this->facebook->getaccessToken(); 
    $query = '
        SELECT first_name, last_name, name, uid,pic_square FROM user
        WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me() ) 
        ORDER BY name';


         // I have tried running the query by getting access token and supplying it and without and still have the same problem.

    //$FQL = array ( "method" => "fql.query", "query" => $query, "access_token" => $access_token);
        $FQL = array ( "method" => "fql.query", "query" => $query);

    $data = $this->facebook->api($FQL);     

    return $data;           

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可爱咩 2024-12-23 15:32:43

我将关闭它,因为在进行更多测试后,我似乎无法一致地重新创建该行为。在 Mac 上使用 Chrome 时似乎会出现此错误,但在其他浏览器中不会出现此错误,而且目前在 PC 上的 Chrome 中也不会出现该错误。我做的进一步测试是进入 Chrome 设置并仅从 facebook.com 删除 cookie,但仍然没有清除它。只有清除所有 cookie 才能解决问题。

到目前为止,没有人对此提出任何建议(而且我无法在网络上找到任何其他参考资料),这一事实让我想知道这是否只是影响我的特定设置的因素。

I'm going to close this as after carrying out some more tests I can't appear to recreate the behaviour consistently. It seems to bring up the error when using Chrome on a Mac but not in other browsers and not so far in Chrome on a PC. A further test I did was to go into the Chrome settings and delete cookies from facebook.com only and still that did not clear it. Only clearing all cookies would cure the problem.

The fact that no-one has offered any suggestions on this so far (and I'm unable to find any other references to it on the web) makes me wonder if this is just something affecting my particular set up.

呆橘 2024-12-23 15:32:43

在我将 access_token 添加到我的 fql 查询中后,这出现在我的应用程序中。我再次删除它,错误仍然存​​在。我的问题似乎是我在没有事先验证(登录网址)的情况下调用了该函数。不知怎的,后来它起作用了。希望这有帮助。

This appeared in my application after i added an access_token to my fql-query. i removed it again and the error remained. my problem SEEMS to have been that i called the function without a prior authentifcation (login-url). somehow it worked afterwards. hope this helps.

酒废 2024-12-23 15:32:43

我也有这个错误。我暂时解决了。只需卸载页面上的应用程序,然后重新登录应用程序即可。它应该工作正常。但这不是永久的解决方案。要卸载应用程序,

设置->应用程序 ->单击相应应用程序上的 x 按钮。

I'm also got this error. I solved it temporary. Just uninstall the apps on your page and then logged in apps again. It should be working fine. But its not permanent solution. To uninstall apps,

settings -> apps -> click x button on corresponding apps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文