【问题标题】:Facebook JSON Service is not retrieving more than 1000 facebook friendFacebook JSON 服务没有检索超过 1000 个 Facebook 朋友
【发布时间】:2012-08-01 18:06:10
【问题描述】:

我在下面的代码中遇到问题,有人可以解决吗? 这是我的代码说明:

$friends=get_data(https://graph.facebook.com/".$facbookid."/friends?access_token=".Useraccess_token);

这是 get_data 函数,它返回适当的数据:

function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

然后我使用 JSON SERVICE:

$json = new Services_JSON();
$friends = $json->decode($friends);
echo "print data".$friends->data;
if (isset($friends->data))
    {   
        foreach($friends->data as $friend) 
        {
            $i++;
            $friendList[] = $friend->id;   
        }
    }

问题是,当我只有 1000 个朋友时,它正在检索数据。但是朋友超过1000就不行了。

事实上,我用过$friends = $json->decode($friends,true); 等。 谁能帮帮我?

【问题讨论】:

标签: php facebook facebook-graph-api developer-tools


【解决方案1】:

Facebook 的图形 API 会限制结果的数量,以防止它(或您)遭受性能不佳或内存不足的困扰。您需要使用the paging features that the API provides,即limitsinceuntil参数。

最好不要更改默认限制,除非你有充分的理由(不打扰页面不是一个好理由)。有用的是,所有结果还包含一个 paging 结构,告诉您下一页(和上一页)的 URL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多