dongmanni6916 2018-11-19 11:27
浏览 591
已采纳

Facebook API(PHP):获取完整的广告列表

I am using Facebook API to fetch the full Ads list.

The Code is working, But it return only 25 Ad in case of i have 150+ Ad in my account.

I guess that happens because of the query limits on the Facebook API.

My Code:

$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->read();

$fields_adset = array(
  AdSetFields::ID,
  AdSetFields::NAME,
  AdSetFields::CAMPAIGN_ID,
  AdSetFields::STATUS,
);

$ads = $account->getAds($fields_adset);

foreach ($ads as $adset) {
    $adset_id = $adset->{AdSetFields::ID};
    echo  $adset_id;
    //print_r($adset);
    //exit();
}

So, they mentioned in the documentation that :

Use Asynchronous Requests to query a huge amount of data

Reference (1) : https://developers.facebook.com/docs/marketing-api/best-practices/

Reference (2) : https://developers.facebook.com/docs/marketing-api/insights/best-practices/#asynchronous

But, I can't apply that "Asynchronous" requests to my code to fetch the Full Ad List,

Please help me to fetch the full Ads list

Thank you.

  • 写回答

1条回答 默认 最新

  • dtkyayvldeaqhl7151 2018-11-19 14:15
    关注

    You should implement pagination (or request a limit more high). With the PHP SDK you can implement the cursor as described in the doc here or more simply set the Implicit Fetching, as example:

    ..
    use FacebookAds\Cursor;
    
    ...
    Cursor::setDefaultUseImplicitFetch(true);
    
    
    $account = new AdAccount('act_<AD_ACCOUNT_ID>');
    $account->read();
    
    $fields_adset = array(
      AdSetFields::ID,
      AdSetFields::NAME,
      AdSetFields::CAMPAIGN_ID,
      AdSetFields::STATUS,
    );
    
    $ads = $account->getAds($fields_adset);
    
    foreach ($ads as $adset) {
        $adset_id = $adset->{AdSetFields::ID};
        echo  $adset_id;
        //print_r($adset);
        //exit();
    }
    

    Hope this help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器