2013-09-23 23 views
0

我試圖讓一大羣朋友的個人資料,我得到的錯誤:Facebook的PHP SDK「在批處理消息請求過多的最大批量大小爲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; 
} 
+3

你不使用你生成您的API調用的JSON你的$塊變量,但仍然是原來的,未修改$請求...... D'哦! – CBroe

+1

...添加您的評論作爲答案,我會批准它。我只是要去把我的頭靠在牆上幾個小時。 – rich97

回答

2

你不使用你的$塊變量在您爲您的API調用的JSON,但仍然是原來的,未修改$請求。

快樂地一聲:-)