如何批量请求adset指标

时间:2015-09-11 03:42:50

标签: php facebook batch-processing facebook-marketing-api

我有一个大约260个广告系列ID的列表,我希望获得每个广告系列ID的所有广告集数据。

我正在使用以下内容来请求一个广告系列ID,但是如果我在循环中运行它并且很快达到我的用户请求限制。

$campaign = new AdCampaign($campaign_id);
$adsets = $campaign->getAdSets($fields);

我正在关注https://developers.facebook.com/docs/marketing-api/guides/chapter-6-ads-management#sets,目前正在使用他们的建议:

use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Fields\AdSetFields;

$fields = array(
  AdSetFields::NAME,
  AdSetFields::START_TIME,
  AdSetFields::END_TIME,
  AdSetFields::DAILY_BUDGET,
  AdSetFields::LIFETIME_BUDGET,
);

$campaign = new AdCampaign('<CAMPAIGN_GROUP_ID>');
$adsets = $campaign->getAdSets($fields);

提前致谢。

1 个答案:

答案 0 :(得分:1)

使用Facebook的批量请求方法为每个广告系列https://developers.facebook.com/docs/graph-api/making-multiple-requests#multiple_methods

请求字段

PHP Ads SDK does not support FB batch requests using its object wrappers但您可以轻松地使用常规API包装器。例如:

$response = $api->call('/', 'POST', array('batch' => $json_string));

其中$ api是Facebook \ Api的一个实例,而$ json_string是一个JSON编码的adset字段批量操作请求数组。 JSON应类似于以下示例(使用API​​版本2.4和组合的广告系列组ID 1000001和1000002):

[
    { "method": "GET", 
      "relative_url":"v2.4/1000001?fields=name,start_time,end_time,daily_budget,lifetime_budget"
    },
    { "method": "GET", 
      "relative_url":"v2.4/1000002?fields=name,start_time,end_time,daily_budget,lifetime_budget"
    }
]