facebook-graph-apifacebook-ads-apifacebook-marketing-apifacebook-java-api

How to download facebook report using Insights API Asynchronous Jobs?


Hi I'am new to facebook marketing API. I want to download account complete report in csv format for which I am using Insights API Asynchronous Jobs , Using which I am able to get "report_run_id" and after that I made api request for this link .Its giving wrong response. Can anybody help me how can download report in csv format.code which i tried is:

OkHttpClient client = new OkHttpClient();    
Request request = new Request.Builder()
  .url("https://www.facebook.com/ads/ads_insights/export_report/?report_run_id=279445242544715&name=reports&format=csv")
  .get()
  .build();

Response response = client.newCall(request).execute();
if(response.isSuccessful()){
 String resposes=response.body().string();
}

Solution

  • I'll give examples using curl, but you should be able to translate these to javascript easily.

    Using the report_run_id, you can query the completeness of the async query, for example:

    curl -G \
      -d 'access_token=<ACCESS_TOKEN>' \
      https://graph.facebook.com/v2.10/1000002
    

    This should eventually give you a completion of 100%:

    {
      "id": "6044775548468",
      "account_id": "1010035716096012",
      "time_ref": 1459788928,
      "time_completed": 1459788990,
      "async_status": "Job Completed",
      "async_percent_completion": 100
    }
    

    You then need to query the report_run_id for with the insights edge:

    curl -G \
      -d 'access_token=<ACCESS_TOKEN>' \
      https://graph.facebook.com/v2.10/<YOUR_REPORT_RUN_ID>/insights