import sys
from googleads import adwords
def main(client):
report_downloader = client.GetReportDownloader(version='v201809')
report = {
'reportName': 'AUDIENCE_PERFORMANCE_REPORT',
'dateRangeType': 'CUSTOM_DATE',
'reportType': 'AUDIENCE_PERFORMANCE_REPORT',
'downloadFormat': 'CSV',
'selector': {
'fields': [ 'AccountDescriptiveName',
'ExternalCustomerId',
'AccountCurrencyCode',
'CampaignId',
'CampaignName',
'CampaignStatus',
'AdGroupName',
'Year',
'MonthOfYear',
'Criteria'
'Device'
'Impressions',
'Clicks',
'VideoViews',
'Cost',
'VideoQuartile25Rate',
'VideoQuartile50Rate',
'VideoQuartile75Rate',
'VideoQuartile100Rate'
],
'dateRange':{'min':'20180101','max':'20181231'}
}
}
path = 'C:/Queries/Geo/csv/audience.csv'
f = open(path, 'wb')
report_downloader.DownloadReport(
report, f,skip_report_header=False, skip_column_header=False,skip_report_summary=False, include_zero_impressions=False)
f.close()
if __name__ == '__main__':
adwords_client = adwords.AdWordsClient.LoadFromStorage()
adwords_client.SetClientCustomerId('899-840-8275')
main(adwords_client)
------------------------------------------------------------------------------------------------Error
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Wunderman\Google_Adwords_API\Queries\RUN> & C:/Wunderman/Python36/python.exe c:/Wunderman/Google_Adwords_API/Queries/Geo/Audience_file.py
Your default encoding, cp65001, is not UTF-8. Please run this script with UTF-8 encoding to avoid errors.
Request Summary: {'clientCustomerId': '899-840-8275', 'includeZeroImpressions': 'False', 'server': 'adwords.google.com', 'skipColumnHeader': 'False', 'skipReportHeader': 'False', 'skipReportSummary': 'False', 'isError': True, 'errorMessage': '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><reportDownloadError><ApiError><type>ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT</type><trigger>CriteriaDeviceImpressions</trigger><fieldPath></fieldPath></ApiError></reportDownloadError>'}
Traceback (most recent call last):
File "C:\Wunderman\Python36\lib\site-packages\googleads\adwords.py", line 1686, in _DownloadReportAsStream
response = self.url_opener.open(request)
File "C:\Wunderman\Python36\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\Wunderman\Python36\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Wunderman\Python36\lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "C:\Wunderman\Python36\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Wunderman\Python36\lib\urllib\request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Wunderman/Google_Adwords_API/Queries/Geo/Audience_file.py", line 47, in <module>
main(adwords_client)
File "c:/Wunderman/Google_Adwords_API/Queries/Geo/Audience_file.py", line 41, in main
report, f,skip_report_header=False, skip_column_header=False,skip_report_summary=False, include_zero_impressions=False)
File "C:\Wunderman\Python36\lib\site-packages\googleads\common.py", line 543, in Wrapper
return utility_method(*args, **kwargs)
File "C:\Wunderman\Python36\lib\site-packages\googleads\adwords.py", line 1337, in DownloadReport
output, **kwargs)
File "C:\Wunderman\Python36\lib\site-packages\googleads\adwords.py", line 1610, in _DownloadReport
response = self._DownloadReportAsStream(post_body, **kwargs)
File "C:\Wunderman\Python36\lib\site-packages\googleads\adwords.py", line 1703, in _DownloadReportAsStream
raise error
googleads.errors.AdWordsReportBadRequestError: Type: ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT
Trigger: CriteriaDeviceImpressions
Field Path: None
PS C:\Wunderman\Google_Adwords_API\Queries\RUN>