Please take a look at the script below and let me know where i went wrong..

function main() {
  var ACCOUNTS = ['xxx-xxx-xxx'];
  var ADWORDS_REPORT = 'KEYWORDS_PERFORMANCE_REPORT';
  var FILTER = 'Impressions > 0';
  var DATE_RANGE = 'LAST_30_DAYS';
  var COLUMNS = [
     'AccountDescriptiveName'
    ,'Date'
    ,'CampaignName'
    ,'AdGroupName'
    ,'Keywordtext'
    ,'ConversionsManyPerClick'
    ,'Id'
    ,'ExternalCustomerId'
    ,'CreativeDestinationUrl'
    ,'Clicks'
    ,'Impressions'
    ,'Ctr'
    ,'AverageCpc'
    ,'Cost'
    ,'AveragePosition'
    ,'CustomerDescriptiveName'
    ,'PrimaryCompanyName'
  ];
  var REPORT_NAME = 'XXX-XXX-XXX';

  
  var adwords_columns = COLUMNS.join(',');  
  var mccAccount = AdWordsApp.currentAccount();
  var childAccounts = MccApp.accounts().withIds(ACCOUNTS).get();
  var childAccount = childAccounts.next();

  MccApp.select(childAccount);

  var report = KeywordsPerformance.report(
    'SELECT ' + keywords_columns +
    ' FROM ' + keywords_REPORT +
    ' WHERE ' + FILTER +
    ' DURING ' + DATE_RANGE);
  
  csv = '';
  for(i = 0; i < COLUMNS.length; i++) {
    csv += i === 0 ? '' : ','
    csv += COLUMNS[i];
  }
  var rows = report.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    csv += '\n';
    for(i = 0; i < COLUMNS.length; i++) {
      csv += i === 0 ? '' : ','
      csv += row[COLUMNS[i]];
    }
  }

  DriveApp.createFile(REPORT_NAME, csv, MimeType.CSV);
}

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/31b4078a-2c73-4362-9aa6-e0325b4f5da5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to