1

我正在尝试使用 facebook 的 java sdk 来生成广告报告。我主要按照示例代码,使用 new AdAccount(ad_account_id, context).getInsights() 来检索数据。但是对于 java sdk,我只能检索部分数据。我不确定我使用的是正确的 API。

    import com.facebook.ads.sdk.*;

    import java.util.ArrayList;
    import java.util.List;
    import config.fbreporting.gettyimages.com.Config;

    public class Sample_code {
        public static void main(String args[]) throws APIException {
            String access_token = Config.ACCESS_TOKEN;
            String ad_account_id = Config.AD_ACCOUNT_ID;
            String app_secret = Config.APP_SECRET;
            APIContext context = new APIContext(access_token).enableDebug(true);
            List<AdsInsights.EnumBreakdowns> breakdowns = new ArrayList<>();
            List<AdsInsights.EnumSummary> summaries = new ArrayList<>();


            APINodeList<AdsInsights> adsInsights =  new AdAccount(ad_account_id, context)
                .getInsights()
                .setLevel(AdsInsights.EnumLevel.VALUE_AD)
                .setFiltering("[{\"field\":\"impressions\",\"operator\":\"GREATER_THAN\",\"value\":\"0\"}]")
//                .setBreakdowns(List<AdsInsights.EnumBreakdowns.VALUE_>)
                .setBreakdowns(breakdowns)
                .setTimeRange("{\"since\":\"2017-08-13\",\"until\":\"2017-09-12\"}")
                .requestField("account_id")
                .requestField("account_name")
                .requestField("ad_name")
                .requestField("adset_id")
                .requestField("adset_name")
                .requestField("ad_id")
                .requestField("actions")
                .requestField("unique_clicks")
                .requestField("unique_inline_link_clicks")
                .requestField("impressions")
                .requestField("reach")
                .requestField("relevance_score")
                .requestField("campaign_id")
                .requestField("campaign_name")
                .requestField("total_action_value")
                .requestField("social_impressions")
                .requestField("spend")
                .requestField("total_actions")
                .requestField("total_conversion_value")
                .requestField("clicks")
                .requestField("date_start")
                .requestField("date_stop")
//                .requestField("delivery")
//                .requestField("result_rate")
//                .requestField("results")
//                .requestField("cost_per_result")

                .execute();
        }
    }

如果我用这种方式,它会返回:

{
   "error": {
      "message": "(#100) result is not valid for fields param. please check https://developers.facebook.com/docs/marketing-api/reference/ads-insights/ for all valid values",
      "type": "OAuthException",
      "code": 100,
      "fbtrace_id": "ALSFEzwK4YP"
   }
}

交付 result_rate 结果 cost_per_result

有谁知道在哪里可以获得这些字段?

另一个问题是我无法按天设置细分。AdsInsights.EnumSummary 中没有此 VALUE。

4

1 回答 1

0

对于按天细分,您需要设置参数 time_increment = 1。

于 2019-10-20T21:55:58.587 回答