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) 

Tag:google-ads-api, python

3 comments.

  1. Riley Runnoe

    Based upon your version='v201809' you are not using the most up to date version of the google ads api. That version of the API is scheduled for deprecation in spring 2022.

    The newest version of the google ads api now uses a query language for their reporting examples.

    Google ads provides a mapping for common reports into the fields required in their query language.

    Once your client is authenticated with a newer version of the API, you can post the Google Ads query to the client.

    from google.ads.googleads.client import GoogleAdsClient client = GoogleAdsClient.load_from_storage("creds") service = client.get_service("GoogleAdsService", version="v9") #query below pulls all accounts that your MCC has access to query = """ SELECT customer_client.client_customer, customer_client.level, customer_client.manager, customer_client.id FROM customer_client WHERE customer_client.manager != True """ search_request = client.get_type("SearchGoogleAdsStreamRequest") search_request.customer_id = "1234adswordscustomer_id" search_request.query = query response = service.search_stream(search_request)
    1. uzrsa

      Hi there! I just know if version 9 is deprecated from google ads, if I want to use the newest version of API google ads which is version 10, did I must change the version to v10? Thanks!

    2. Riley Runnoe

      I am not sure about the breaking differences between v9 and v10. You would need to check release documentation to make sure that you're not using parts of the graph that were deprecated in the v9 to v10 switch.

Add a new comment.