如何使用Insights API Asynchronous Jobs下载facebook报告?

时间:2017-10-16 12:24:25

标签: facebook-graph-api facebook-ads-api facebook-marketing-api facebook-java-api

您好我是facebook marketing API的新手。我想以csv格式下载帐户完整报告,我正在使用Insights API异步作业,使用我可以获得" report_run_id"之后我向this link提出了api请求。它给出了错误的回复。任何人都可以帮助我如何在csv format.code下载报告,我试过:

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();
}

1 个答案:

答案 0 :(得分:1)

我将使用curl给出示例,但您应该能够轻松地将这些转换为javascript。

使用report_run_id,您可以查询异步查询的完整性,例如:

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

这最终会让你完成100%:

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

然后,您需要使用洞察边缘查询report_run_id:

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