繁体   English   中英

Facebook PHP SDK“批处理消息中的请求太多。 最大批量为50“

[英]Facebook PHP SDK “Too many requests in batch message. Maximum batch size is 50”

我正在尝试获取一大群朋友的个人资料,我收到错误:

Too many requests in batch message. Maximum batch size is 50

来自API。 现在我理解错误消息,但我认为我构建了该函数来缓解此错误。 我特意以50的块为单位进行调用。我没有在任何调用它的方法中更改$ chunk_size,所以我真的不知道这里发生了什么。

这是吐出错误的函数:

protected function getFacebookProfiles($ids, array $fields = array('name', 'picture'), $chunk_size = 50)
{
    $facebook = App::make('Facebook');
    $fields = implode(',', $fields);

    $requests = array();
    foreach ($ids as $id) {
        $requests[] = array('method' => 'GET', 'relative_url' => "{$id}?fields={$fields}");
    }

    $responses = array();
    $chunks = array_chunk($requests, $chunk_size);
    foreach ($chunks as $chunk) {
        $batch = json_encode($requests);
        $response = $facebook->api("?batch={$batch}", 'POST');

        foreach ($response as &$profile) {
            $profile = json_decode($profile['body']);

            if (empty($profile->picture->data)) {
                // something has gone REALLY wrong, this should never happen but if it does we'll have more debug information
                if (empty($profile->error->message)) {
                    throw new Exception('Unexpected error when retrieving user information for IDs:' . implode(', ', $ids));
                }

                $profile->error = (array) $profile->error;
                throw new FacebookApiException((array) $profile);
            }

            $profile->picture = $profile->picture->data;
        }

        $responses = array_merge($responses, $response);
    }

    return $responses;
}

您没有在为API调用生成的JSON中使用$ chunk变量,但仍然是原始的未修改的$ requests。

快乐砰的一声:-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM