是的,這是正確的。
我的策略是在加載批處理請求時創建一個跟蹤數組。此數組將我的關聯數組的關鍵字與我發佈批次的數字順序關聯起來。當我遍歷結果時,我使用一個計數器來遍歷跟蹤數組並提取適當的關聯數組索引。然後,我使用它來更新關聯數組和該批處理操作的結果。
如果批處理支持'name'參數並且每個響應都返回該參數,那將會很好。但只出現如果你使用的名稱創建批處理依賴的工作: https://developers.facebook.com/docs/reference/api/batch/
加載了批次:
foreach ($campaigns as $title => $campaign) {
if (count($batch) == 20) {
$batches[] = $batch;
$batch = array();
}
$titles[] = $title; #TRACKING array;
$body = http_build_query($campaign);
$body = urldecode($body);
$batch[] = array(
'method' => 'POST',
'relative_url' => "/act_{$act}/adcampaigns",
'body' => $body
);
}
加工批次:
if ($batch) {
$batches[] = $batch;
$counter = 0;
foreach ($batches as $batch) {
$params = array(
'access_token' => $access_token,
'batch' => json_encode($batch)
);
$responses = $facebook->api('/', 'POST', $params);
foreach ($responses as $response) {
$response = json_decode($response['body'], 1);
$campaign_id = $response['id'];
$title = $titles[$counter]; #RETRIEVING THE INDEX FROM THE TRACKING ARRAY
$campaigns[$title]['campaign_id'] = $campaign_id;
$counter++; #INCREMENTING THE COUNTER
}
}
}