Bulk upload

Bulk upload from Google Drive

function bulkUploadFromGoogleDrive() {
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates.
  // You can upload a CSV file, or an EXCEL sheet.
  var file = DriveApp.getFilesByName('BulkCampaignUpload.csv').next();
  var upload = AdWordsApp.bulkUploads().newFileUpload(file);
  upload.forCampaignManagement();

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Bulk upload from remote server

function bulkUploadFromRemoteServer() {
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates.
  var dataUrl = 'INSERT_CSV_FILE_URL_HERE';

  var blob = UrlFetchApp.fetch(dataUrl)
      .getBlob()
      .getAs(MimeType.CSV);

  var upload = AdWordsApp.bulkUploads().newFileUpload(blob);
  upload.forCampaignManagement();

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Bulk upload from Google Sheets

function bulkUploadFromGoogleSpreadsheet() {
  // The format of this spreadsheet should match a valid bulk upload template.
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates.
  var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';
  var spreadSheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = spreadSheet.getActiveSheet();

  var upload = AdWordsApp.bulkUploads().newFileUpload(sheet);
  upload.forCampaignManagement();

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Bulk upload from AdWords reports

function bulkUploadFromAdWordsReports() {
  // Run a report to fetch all campaigns that spent more than $1000
  // this month.
  var query = 'SELECT CampaignId,CampaignName,CampaignStatus,Amount ' +
      'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
      'WHERE Amount > 1000000000 ' +
      'DURING THIS_MONTH';
  var report = AdWordsApp.report(query);

  // Create an upload with the report columns.
  var upload = AdWordsApp.bulkUploads().newCsvUpload([
      report.getColumnHeader('CampaignId').getBulkUploadColumnName(),
      report.getColumnHeader('CampaignName').getBulkUploadColumnName(),
      report.getColumnHeader('CampaignStatus').getBulkUploadColumnName()]);
  upload.forCampaignManagement();

  var rows = report.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    // Pause the campaigns.
    row.CampaignStatus = 'paused';

    // Convert the report row into an upload row.
    upload.append(row.formatForUpload());
  }

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Create/update campaigns

function createOrUpdateCampaigns() {
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates and their column names.
  var columns = [
    'Campaign', 'Budget', 'Bid Strategy type', 'Campaign type'
  ];

  var upload = AdWordsApp.bulkUploads().newCsvUpload(
      columns, {moneyInMicros: false});

  // AdWords identify existing campaigns using its name. To create a new
  // campaign, use a campaign name that doesn't exist in your account.
  upload.append({
    'Campaign': 'Test Campaign 1',
    'Budget': 234,
    'Bid Strategy type': 'cpc',
    'Campaign type': 'Search Only'
  });
  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Retrieve column names in reports

function getColumnsFromReport() {
  var report = AdWordsApp.report('SELECT CampaignName, CampaignStatus ' +
      'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
      'DURING TODAY');
  Logger.log(
      '%s, %s',
      report.getColumnHeader('CampaignName').getBulkUploadColumnName(),
      report.getColumnHeader('CampaignStatus').getBulkUploadColumnName()
  );
}

发送以下问题的反馈:

此网页
AdWords Scripts
AdWords Scripts
需要帮助?请访问我们的支持页面