我想从对 FB 广告的 api 调用中下载 CSV,我已经按照下面的代码在参数中设置了它,调用工作正常,但我只得到一个分页的 JSON 作为响应。我不太确定如何访问CSV报告,响应没有给我任何报告ID或下载链接。如何下载此 CSV?
Using nodejs facebook-nodejs-ads-sdk显示参数信息"export_format"的图像文档:https://developers.facebook.com/docs/marketing-api/reference/adgroup/insights/
var getReport = function(){
console.log("API for FB report has been called")
let ads_insights;
let ads_insights_id;
const logApiCallResult = (apiCallName, data) => {
console.log(apiCallName);
if (showDebugingInfo) {
console.log('Data:' + JSON.stringify(data));
}
};
const fields = [
'ad_name',
'impressions',
'reach',
'spend'
];
const params = {
'export_format': 'csv',
'export_name': new Date() + 'fb-download',
'level' : 'ad',
'filtering' : [],
'breakdowns' : [],
'time_range' : {'since':'2018-01-22','until':'2018-01-23'}
};
new AdAccount(ad_account_id).getInsights(
fields,
params).then((result) => {
logApiCallResult('ads_insights api call complete.', result);
console.log("##########" + result + "#####")
ads_insights_id = result[0].id;
}).catch((error) => {
console.log(error);
});
}
导出实际的报告文件似乎不是官方Facebook Graph API的一部分。
我的解决方案是向以下端点发出 GET 请求:
https://www.facebook.com/ads/ads_insights/export_report/?report_run_id=<REPORT_RUN_ID>&name=<REPORT_FILE_NAME>&format=csv&access_token=<FACEBOOK_API_KEY>
请注意,此端点将输出一个文件,其中包含不断更改的列而不会发出警告,因此它不利于自动数据收集。导出标准化报告的唯一方法是使用 JSON 格式。
此端点的文档很难找到:位于此处。