Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix in get_account_hierarchy #522

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

fix in get_account_hierarchy #522

wants to merge 2 commits into from

Conversation

CefBoud
Copy link

@CefBoud CefBoud commented Oct 23, 2021

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 CefBoud requested a review from a team as a code owner October 23, 2021 13:53
@google-cla
Copy link

google-cla bot commented Oct 23, 2021

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

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

@BenRKarl BenRKarl added the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Oct 27, 2021
@kokoro-team kokoro-team removed the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Oct 27, 2021
@CefBoud
Copy link
Author

CefBoud commented Nov 6, 2021

@googlebot I signed it!


# login_customer_id is required to query child accounts that are not
# directly accessible to the OAuth Credentials
client.login_customer_id = str(seed_customer_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to convert this to a str as it's already defined as such by argparse here

# login_customer_id is required to query child accounts that are not
# directly accessible to the OAuth Credentials
client.login_customer_id = str(seed_customer_id)
googleads_service = client.get_service("GoogleAdsService")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the first googleads_service initialization on line 43 can be removed, then line 79 can be updated to use customer service:

customer_id = customer_service.parse_customer_path(
    customer_resource_name
)["customer_id"]

@ThatsJustCheesy
Copy link

ThatsJustCheesy commented Nov 18, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants