簡體   English   中英

在FB marketing api中,有一個export_format選項:'csv',如何下載csv文件?

[英]In the FB marketing api, there is an option to export_format: 'csv', how do I download the csv file?

我想從我的api調用中下載一個CSV到FB廣告,我已根據下面的代碼在參數中設置它,調用工作正常,但我只得到一個分頁的JSON作為響應。 我不太確定如何訪問CSV報告,響應會給我任何報告ID或下載鏈接。 如何下載此CSV?

使用nodejs facebook-nodejs-ads-sdk image顯示參數信息'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格式。

這個端點的文檔很難找到: 位於此處。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM