I am trying to get the reports such as geo_performance_report, keywords_perfromance_report etc. but I am unable to figure how do to this with the new version of google-ads api. I tried this way trying to use the new google-ads but was not successful. is there any other ways to automate this process using Python.
def googleads_report(client, client_id, report_type, columns, start_date, end_date): client.SetClientCustomerId(client_id) report_downloader = googleads_client.GetReportDownloader(version="v201809") report = { 'reportName': 'report-google-campaign-performance', 'dateRangeType': 'CUSTOM_DATE', 'reportType': report_type, 'downloadFormat': 'CSV', 'selector': { 'fields': columns, 'dateRange': {'min': start_date, 'max': end_date} } } file = io.StringIO(report_downloader.DownloadReportAsString( report, skip_report_header=True, skip_column_header=True, skip_report_summary=True, include_zero_impressions=False) ) df = pd.read_csv(file, names=columns) return df def main(client, customer_id): keyword_columns = [ 'Date', 'AccountDescriptiveName', 'AdGroupId', 'AdGroupName', 'AdGroupStatus', 'CampaignId', 'CampaignName', 'CampaignStatus', 'CpcBid', 'Criteria', 'CriteriaDestinationUrl', 'ExternalCustomerId', 'FirstPageCpc', 'FirstPositionCpc', 'Id', 'KeywordMatchType', 'Labels', 'QualityScore', 'SearchImpressionShare', 'Status', 'TopOfPageCpc', 'Clicks', 'Conversions', 'Cost', 'ConversionValue', 'Impressions', 'ViewThroughConversions' ] report_types = [ 'KEYWORDS_PERFORMANCE_REPORT' ] for report in report_types: base_df = pd.DataFrame() if report == 'CAMPAIGN_PERFORMANCE_REPORT': table_suffix = 'campaigns' #columns = campaign_columns elif report == 'KEYWORDS_PERFORMANCE_REPORT': table_suffix = 'keywords' columns = keyword_columns elif report == 'AD_PERFORMANCE_REPORT': table_suffix = 'ads' #columns = ad_columns start_date = '2019-01-01' df = googleads_report(client,customer_id, report, columns, start_date, yesterday) df = df.applymap(str) # Powershell output print(df.head()) # csv output df.to_csv('my_path' + table_suffix + '.csv') if __name__ == "__main__": # GoogleAdsClient will read the google-ads.yaml configuration file in the # home directory if none is specified. googleads_client = GoogleAdsClient.load_from_storage(path="mypath") today = datetime.now().date() yesterday = today - timedelta(days=1) thirty_days_ago = today - timedelta(days=30) try: main( googleads_client, "#######") except GoogleAdsException as ex: print( f'Request with ID "{ex.request_id}" failed with status ' f'"{ex.error.code().name}" and includes the following errors:' ) for error in ex.failure.errors: print(f'\tError with message "{error.message}".') if error.location: for field_path_element in error.location.field_path_elements: print(f"\t\tOn field: {field_path_element.field_name}") sys.exit(1)