问题
I'm looking to download a CSV from my api call to FB ads, I've set it in the parameters as per the code below, the call works fine but I only get a paginated JSON as a response. I'm not quite sure how to access the CSV report, the response doenst give me any report ID or download link. How can I download this CSV?
Using nodejs facebook-nodejs-ads-sdk image showing the parameter information 'export_format' Documentation: 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);
});
}
回答1:
Exporting actual report files doesn't seem to be a part of the official Facebook Graph API.
My solution was to make a GET request to the following endpoint:
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>
Please note that this endpoint will output a file with columns that constantly change without warning, so its not good for automated data collection. The only way to export standardized reports is in the JSON format.
The docs for this endpoint are sort of hard to find: located here.
来源:https://stackoverflow.com/questions/48410866/in-the-fb-marketing-api-there-is-an-option-to-export-format-csv-how-do-i-do