问题描述
我正在使用Facebook ads api获取帐户Campaign数据.我在这里所做的是获取所有广告系列的列表,并为每个广告系列进行forloop获取广告系列统计信息
I am working on Facebook ads api to get the account Campaign data.What I am doing here is I get list of all campaigns and doing forloop of each campaign get Campaign stat
$campaignSets = $account->getCampaigns(array(
CampaignFields::ID,
CampaignFields::NAME
));
foreach ($campaignSets as $campaign) {
$campaign = new Campaign($campaign->id);
$fields = array(
InsightsFields::CAMPAIGN_NAME,
InsightsFields::IMPRESSIONS,
InsightsFields::UNIQUE_CLICKS,
InsightsFields::REACH,
InsightsFields::SPEND,
InsightsFields::TOTAL_ACTIONS,
InsightsFields::TOTAL_ACTION_VALUE
);
$params = array(
'date_preset' => InsightsPresets::TODAY
);
$insights = $campaign->getInsights($fields, $params);
}
执行上述代码时,我收到错误消息,提示(#17)达到了用户请求限制.
when executing above code I am getting error as (#17) User request limit reached.
有人可以帮助我解决此类错误吗?
Can anyone help me how to solve this kind of error?
谢谢,罗纳克·沙(Ronak Shah)
Thanks,Ronak Shah
推荐答案
您应该考虑针对该adaccount生成一个报告,该报告返回所有广告系列的见解,这将大大减少所需的请求数量.
You should consider generating a single report against the adaccount which returns insights for all of your campaigns, this should reduce the number of requests required significantly.
Cursor::setDefaultUseImplicitFetch(true);
$account = new AdAccount($account_id);
$fields = array(
InsightsFields::CAMPAIGN_NAME,
InsightsFields::CAMPAIGN_ID,
InsightsFields::IMPRESSIONS,
InsightsFields::UNIQUE_CLICKS,
InsightsFields::REACH,
InsightsFields::SPEND,
InsightsFields::TOTAL_ACTIONS,
InsightsFields::TOTAL_ACTION_VALUE,
);
$params = array(
'date_preset' => InsightsPresets::TODAY,
'level' => 'ad',
'limit' => 1000,
);
$insights = $account->getInsights($fields, $params);
foreach($insights as $i) {
echo $i->campaign_id.PHP_EOL;
}
这篇关于FB Ads API(#17)已达到用户请求限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!