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'.

Tag:google-ads-api, python, google-oauth, service-accounts, google-api-python-client

Add a new comment.