google-ads-python icon indicating copy to clipboard operation
google-ads-python copied to clipboard

fix in get_account_hierarchy

Open CefBoud opened this issue 4 years ago • 3 comments

I had the same error mentionned in #441 using code based on examples/account_management/get_account_hierarchy.py.

Error with message "User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid".

The error occurs in the client.get_service("GoogleAdsService").search method because the client doesn't have a login_customer_id .

Assigning the seed_customer_id (which is part of the accessible customers) to GoogleAdsClient that generates GoogleAdsService worked for me.

for seed_customer_id in seed_customer_ids:
        client.login_customer_id = str(seed_customer_id)
        googleads_service = client.get_service("GoogleAdsService")

CefBoud avatar Oct 23 '21 13:10 CefBoud

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] avatar Oct 23 '21 13:10 google-cla[bot]

@googlebot I signed it!

CefBoud avatar Nov 06 '21 09:11 CefBoud

The changes here fixed the example for me. Previously, I was getting "User doesn't have permission to access customer."

The final patched code:

for seed_customer_id in seed_customer_ids:
    client.login_customer_id = seed_customer_id
    googleads_service = client.get_service("GoogleAdsService")

using @BenRKarl's suggested change as well (customer_service.parse_customer_path above)

ThatsJustCheesy avatar Nov 18 '22 22:11 ThatsJustCheesy