duanbei2914 2015-08-25 23:50
浏览 37
已采纳

Facebook图形PHP API批量请求

I am trying to get to get clicks and spend data for ad campaigns.

I am currently getting all ad campaign ID's with a curl request which returns about 260 ID's.

I want to make a batch request and get the clicks, spend, start and end dates for each ID.

I have found the PHP SDK FacebookRequest() function very confusing so have been trying to make cURL requests.

Would really appreciate some help because I am just stumped at the moment. Is it best to use to FacebookRequest() function or can I continue using the cURL requests?

Not sure if I am on the right track but essentially what I have at the moment is all the campaign ID's which I group with a method, relative_url and body and then pass to a requestHandler function. The code is as follows:

    $ad_account_ids = <ad_account_id>;

    $ad_campaign_ids = FbAdCampaign::all()->lists('ad_campaign_id')->toArray();

    foreach ($ad_campaign_ids as $key => $value) {
        $ad_campaign_ids[$key] = array(
            "method" => "GET",
            "relative_url" => "v2.4/act_".$ad_account_ids."/adgroups",
            "body" => "campaign_id=".$value."&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"US\"]}&name=test1"
            );
        $fields[] = array(
            'access_token' => $access_token,
            'batch' => $ad_campaign_ids[$key]
            );

    // $url = 'https://graph.facebook.com/v2.4/act_'.$ad_campaign_ids.'/adcampaign_groups?access_token='.$access_token;
    $url = 'https://graph.facebook.com/';

    $data = RequestHandler::curlRequest($url);
  • 写回答

1条回答 默认 最新

  • dto5637 2015-08-26 03:50
    关注

    Ok got it.

    Had to prepend the /GET data to the end of the URL to pass to the request handler.

    as follows:

    $url = 'https://graph.facebook.com/v2.3/act_'.$ad_account_ids.'/adcampaign_groups?access_token='.$access_token;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料