0

我正在尝试使用脚本将一些报告数据从 Google DCM 提取到 Google 表格。我确实修改了此处所需的参数并尝试运行此文件。但我得到这个错误ReferenceError: DoubleClickCampaigns is not defined我在这里做错了什么。

////// UPDATE WITH YOUR DCM REPORT/PROFILE ID & THE GOOGLE SHEETS URL AND TAB NAME ////////////////
                                                                                                  /
var reportId = XXXXXXXXXX;                                                                        /
var profileId = XXXXXXXX;                                                                         /
                                                                                                  /
var SPREADSHEET_URL = 'XXXXXXXXXXXXXX'                                                            /
var TAB_NAME = 'XXXXXXX'                                                                          /
                                                                                                  /
////// DO NOT TOUCH ANYTHING BELOW ////////////////////////////////////////////////////////////////

function DCMdownload() {

  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(TAB_NAME);

  var httpOptions = {'headers': {'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()}};       
  var additionalParameters = {'synchronous': 'true'};
  var ReportFile = DoubleClickCampaigns.Reports.run(profileId, reportId, additionalParameters);
  var ReportFileID = (ReportFile.id);

  var newReportFile = DoubleClickCampaigns.Files.get(reportId, ReportFileID);
  if(newReportFile.urls) {var httpOptions = {'headers': {'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()}};

  var csvContent = UrlFetchApp.fetch(newReportFile.urls.apiUrl, httpOptions).getContentText();
  var csvData = Utilities.parseCsv(csvContent);
  sheet.clearContents().clearFormats();
  sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
}
4

1 回答 1

1

我相信你的目标如下。

  • 您想知道错误消息的原因ReferenceError: DoubleClickCampaigns is not defined并将其删除。

为此,这个答案怎么样?

我认为您的错误消息的原因是高级 Google 服务未启用“DCM/DFA Reporting And Trafficking API”。请问您能否确认“DCM/DFA Reporting And Trafficking API”是否已在 Google 高级服务中启用?请在启用后再次测试。

参考:

于 2020-04-27T22:17:21.310 回答