Posts tagged with google-ads-api

typicallyl in sql, you can use * to mutiply columns, but I am getting an error when trying to do so in my query below within GoogleAds API - anyone face this challenge before.

Code:

import sys, json, io, gzip, sys, os from googleads import adwords import pandas as pd import numpy as np def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):   ga_service = client.get_service("GoogleAdsService")   search_request=client.get_type("SearchGoogleAdsStreamRequest")   search_request.customer_id = customer_id     query = """         SELECT           segments.date,           ad_group.id,           ad_group.name,           campaign.id,           campaign.name,           metrics.impressions,           metrics.clicks,           metrics.clicks*metrics.average_cpc as cost,           metrics.conversions,           metrics.ctr,           metrics.average_cpc,           metrics.cost_per_conversion         FROM ad_group         where segments.date BETWEEN 20220427 AND 20220428                   limit 10         """                 print(query)   search_request.query = query      stream = ga_service.search_stream(search_request)      for batch in stream:     for row in batch.results:       print(row)         return 1 

Error:

Request made: , Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId: TevDX_z7WYF-AWUZBMVbnw, IsFault: True, FaultMessage: Error in query: unexpected input *. Traceback (most recent call last): 

Google Ads API recently discontinued an old version - https://ads-developers.googleblog.com/2021/04/upgrade-to-google-ads-api-from-adwords.html.

That being said I am trying to adjust my query to new api standards, and getting the strangest error "unexpected input DURING" -- more detail below. It would seem to be correct per this doc:https://developers.google.com/google-ads/api/docs/samples/get-hotel-ads-performance

Note the use of "DURING" in the example SQL query in the doc above.

Below is my error message and further below is script:

ERROR:

SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428 Request made: ClientCustomerId:, Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId:, IsFault: True, FaultMessage:  Error in query: unexpected input DURING. 

script:

import sys, json, io, gzip, sys, os from googleads import adwords import pandas as pd import numpy as np def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):   ga_service = client.get_service("GoogleAdsService")   search_request=client.get_type("SearchGoogleAdsStreamRequest")   search_request.customer_id = customer_id   query = f"SELECT {', '.join(str(x) for x in fields)} FROM {str(report_type[0])} WHERE Status IN {*statuses,} DURING {date_range}"      # query = "SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428"                 print(query)   search_request.query = query      stream = ga_service.search_stream(search_request)      for batch in stream:     for row in batch.results:       print(row)         return 1 

Really sorry if this is the basic question.

I have been searching for two days to find the documentation/sample function to use in apps script that fetches google ads accounts, reports, etc. what I have found all, is the documentation for languages like PHP, python, c, etc and they are giving me tough time understanding them. I know integrating google ads in google sheets is possible as google itself has published an add-on to fetch the reports but can't find any hint either in this platform or in the official documentation. any help will be highly appreciated.

Note: I am seeking help for integrating google ads in google sheets through apps script not ads script. I know there are functions available for ads script even in the documentation but none I found for apps script to the best of my research.

Thanks.

I'm trying to use Google Ads API using service account.
The following works:

from google.ads.googleads.client import GoogleAdsClient from google.oauth2.service_account import Credentials as ServiceAccountCreds oauth2_client = ServiceAccountCreds.from_service_account_file(     filename=key_file, subject=developer_account,     scopes=["https://www.googleapis.com/auth/adwords"] ) google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=oauth2_client,                                     developer_token=self.developer_token) self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9") self.ga_serice.search_stream(customer_id=self.client_customer_id, query =  query) 

I want to to do following with Identity Workload Federation(w/o key):

from google.auth import aws as google_auth_aws from google.ads.googleads.client import GoogleAdsClient credentials = google_auth_aws.Credentials.from_info(json_config_info)  # from workload identity federation credentials = credentials.with_scopes(["https://www.googleapis.com/auth/adwords"]) credentials = credentials.with_subject(self.developer_account) # Build the service object. self.google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=credentials,                                     developer_token=self.developer_token) self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9") self.ga_service.search_stream(customer_id =self.client_customer_id, query =  self.query) 

Which throws error: ERROR:'Credentials' object has no attribute 'with_subject'.

We are trying to implement the Mediation Test Suite but, we are getting the following error message:

Undefined symbols for architecture arm64: "_kGADSimulatorID", referenced from: _GMTSMediationRequest in GoogleMobileAdsMediationTestSuite(GMTSMediationHelper.o)
"_kGADAdSizeBanner", referenced from: -[GMTSBannerAdLoader initWithAdUnitId:rootViewController:] in GoogleMobileAdsMediationTestSuite(GMTSBannerAdLoader.o)
"_kGADAdLoaderAdTypeNative", referenced from: -[GMTSNativeAdLoader initWithAdUnitId:rootViewController:] in GoogleMobileAdsMediationTestSuite(GMTSNativeAdLoader.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)