customer_service = client.get_service("CustomerService") app_list = customer_service.list_accessible_customers().resource_names def customer_query(client, customer_id):     ga_service = client.get_service("GoogleAdsService")     query = """         SELECT             customer.descriptive_name,             customer.currency_code         FROM customer         LIMIT 1"""     request = client.get_type("SearchGoogleAdsRequest")     request.customer_id = customer_id     request.query = query     response = ga_service.search(request=request)     customer = list(response)[0].customer     return customer for entry in app_list:     customer_id = entry.split('/')[1]     entry = customer_query(client, customer_id)     formatted_entry = {'customer_id': customer_id, 'name': entry.descriptive_name, 'currency': entry.currency_code}     apps.append(formatted_entry) return apps 

This seems really convoluted and I'm having to pass around a lot more data than I'd like. Surely there should be a way to just request the details.

Tag:google-ads-api, google-api, python

Only one comment.

  1. dorian

    Your general approach is correct, you'll need to iterate over all accessible Google Ads accounts for the logged in user and then request details for them.

    However, if any of those accounts is a manager account, then you'll want to use the customer_client resource instead as there might be many accounts under that manager account. Consider using a query such as

    SELECT customer_client.id, customer_client.descriptive_name, customer_client.currency_code FROM customer_client

    Also note that in the manager account case, it's possible that you'll receive the same account multiple times if it's reachable from different accessible accounts. See the crudely drawn diagram below for an example:

    ┌───────────────────────┐ │ │ │ User's Google Account │ │ │ ┌────┴───────────────────────┴────┐ │ │ │ │ ┌─────────▼───────────────┐ ┌──────────────▼─────────┐ │ │ │ │ │ Ads Manager Account 1 │ │ Ads Manager Account 2 │ │ │ │ │ └──────────────────────┬──┘ └──────┬─────────────────┘ │ │ │ │ │ │ ┌───▼────────────▼─┐ │ │ │ Ads Account A │ │ │ └──────────────────┘

Add a new comment.