【问题标题】:Facebook Graph Api error "An unexpected error has occurred. Please retry your request later"Facebook Graph Api 错误“发生意外错误。请稍后重试您的请求”
【发布时间】:2017-08-24 07:45:12
【问题描述】:

我正在尝试检索收到此错误的 Facebook 群组中的所有成员:

 array(5) {
    ["message"]=>
    string(66) "An unexpected error has occurred. Please retry your request later."
    ["type"]=>
    string(14) "OAuthException"
    ["is_transient"]=>
    bool(true)
    ["code"]=>
    int(2)
    ["fbtrace_id"]=>
    string(11) "AnfsXcdgM"
  }

这是我的代码:

$this->_facebook = new Facebook\Facebook(array('app_id' => "$app_id",'app_secret' => "$secret",'default_graph_version' => 'v2.10'));

$this->_facebook->setDefaultAccessToken($_SESSION['facebook_access_token']);

$query = "/".$groupID."/members?fields=id,name,link,picture,first_name,last_name";

try{
    $response = $this->_facebook->get($query);
    while($pagesEdge)
    {
     $pageDecoded = json_decode($pagesEdge);
     foreach($pageDecoded as $key => $member)
     {
         $id = $member->id;
     } 
    }
}catch (Facebook\Exceptions\FacebookResponseException $e) {  echo 'Graph returned an error: ' . $e->getMessage(); }

它适用于数百人的团体(即使对于有 10.000 名成员的团体也适用),但我随机发生这种情况。

【问题讨论】:

  • 您是该组的管理员吗?是公共组吗?
  • 我已经尝试过所有的用户权限和组类型。我唯一的问题是大量数据..

标签: facebook facebook-graph-api facebook-javascript-sdk facebook-php-sdk


【解决方案1】:

这可能是由服务器端超时引起的。当我请求大量数据时,我时不时会收到此错误。也许您应该尝试使用 limit 参数(默认应为 25)来限制您的请求。

【讨论】:

  • 是的,尝试导入大量数据时,我不断收到“内部服务器错误”。在一次获得 25 个字段并循环它们后,我仍然收到相同的错误 .-.跨度>
【解决方案2】:

我通过执行一次 100 条数据的 cron 并将下次调用的令牌值放入文件文本中解决了这个问题。

我在查询中添加此字符串,当 $url 中的字段为空时,我退出执行

<?php 

public function updateGroupMembers($groupID)
{
    $tempNext = file_get_contents($this->dirM); //check if the next string token is in the file
    if (!empty($tempNext)) 
    {
        $queryUntil = $tempNext;
    }
    // Sets the default fallback access token so we don't have to pass it to each request
    $this->_facebook->setDefaultAccessToken($_SESSION['facebook_access_token']);
    // Create table name
    $tableName = $groupID . "_Members";

    // Query the Graph API to get all current member's ID and name
    try 
    {
        $query = "/".$groupID."/members?fields=id,name,link,picture,first_name,last_name".$queryUntil; //add the next string to my query
        $response = $this->_facebook->get($query); 
        $pagesEdge = $response->getGraphEdge();    
        // Index for the elements fetched from the API below
        $i = 0;
        // Get current time
        $pageDecoded = json_decode($pagesEdge);
        foreach($pageDecoded as $key => $member)
        {
           /* ...get data and process them... */
        }   

        $temp = $pagesEdge->getMetaData();
        $next = parse_url($temp['paging']['next']);
        parse_str($next['query'], $url);

        $access_token   = '&access_token='.$url['access_token'];
        $fields         = '&fields='.$url['fields'];
        $limit          = '&limit=100';
        $after          = '&after='.$url['after'];

        $res['until'] = $access_token.$fields.$limit.$after;

        file_put_contents($this->dirM, $res['until'], LOCK_EX);

        if ( empty($url['access_token']) || empty($url['fields']) || empty($url['limit']) || empty($url['after']) ) 
        {
            file_put_contents($this->dirM, '', LOCK_EX); //clean my txt file that contains my next string
            die('FINE');
        }

    } catch (Facebook\Exceptions\FacebookResponseException $e) {
        echo 'm2Graph returned an error: ' . $e->getMessage();
        exit;
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        echo 'm2Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多