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

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 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

    点赞 评论 复制链接分享

相关推荐