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 Qt 不小心删除了自带的类,该怎么办
    • ¥15 我需要在PC端 开两个抖店工作台客户端.(语言-java)
    • ¥15 有没有哪位厉害的人可以用C#可视化呀
    • ¥15 可以帮我看看代码哪里错了吗
    • ¥15 设计一个成绩管理系统
    • ¥15 PCL注册的选点等函数如何取消注册
    • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
    • ¥15 Python爬虫程序
    • ¥15 crypto 这种的应该怎么找flag?
    • ¥15 代码已写好,求帮我指出错误,有偿!