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

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

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

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功