facebook java ads sdk how to retrieve "delivery, results,result_rate,cost_per_result", and breakdown by day

461 views Asked by At

I'm trying to use facebook's java sdk to generate the ads report. I mainly followed the Sample code, using new AdAccount(ad_account_id, context).getInsights() to retrieve data. But for the java sdk I could only retrieve partially data. I'm not sure I'm using the correct 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();
        }
    }

If I used this way, it would return:

{
   "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"
   }
}

delivery result_rate results cost_per_result

Is there anyone know where to get these fields?

Another problem is I cannot set the breakdown by Day. There is no this VALUE in AdsInsights.EnumSummary.

1

There are 1 answers

0
JG518 On

For breakdown by day you need to set the param time_increment = 1.