如何使用Insights API异步作业下载Facebook报告?
问题描述:
嗨,我是新的facebook营销API。我想以csv格式下载我正在使用Insights API异步作业的帐户完整报告,使用它可以获得“report_run_id”,然后我提出了对this link的api请求。它给出了错误的响应。任何人可以帮助我如何可以下载CSV format.code报告,我想的是:如何使用Insights API异步作业下载Facebook报告?
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();
}
答
我会给使用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