googleapis / python-analytics-admin

This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-analytics-admin
Apache License 2.0
36 stars 8 forks source link

Delegated credentials error: request had insufficient authentication scopes. #97

Closed Greta991 closed 3 years ago

Greta991 commented 3 years ago

Hello! I'm trying to link a GA4 property and an Google Ads account (https://github.com/googleapis/python-analytics-admin/blob/master/samples/properties_google_ads_links_create.py) using delegated credentials.

Unfortunately the code gives me the following error: 403 Request had insufficient authentication scopes.

This is my code:

credentials = service_account.Credentials.from_service_account_file('my_json.json', scopes=['https://www.googleapis.com/auth/adwords'])

delegated_credentials = credentials.with_subject(MY_EMAIL)

client_ads = AnalyticsAdminServiceClient(credentials=delegated_credentials)
new_google_ads_link = GoogleAdsLink(customer_id='CUSTOMER_ID_GOOGLE_ADS')
google_ads_link = client_ads.create_google_ads_link(parent='properties/123456', google_ads_link=new_google_ads_link)

I have already enabled the Google Ads API in my project and i followed the steps for delegate domain-wide authority to a service account (https://developers.google.com/admin-sdk/directory/v1/guides/delegation).

Anyone have any ideas on how to go about fixing this error? Thank you!

parthea commented 3 years ago

Hi @Greta991,

Please can you try version 0.4.1 and let me know if there is still an issue?

If you're still seeing the problem with 0.4.1, please try updating the scopes. From the reference documentation, it looks like scope https://www.googleapis.com/auth/analytics.edit is required. Please could you try using that scope?

Greta991 commented 3 years ago

Hi, Thank you for your answer. I used google-analytics-admin==0.4.1.

I tried to use the scope https://www.googleapis.com/auth/analytics.edit and it returns this error: 503 Getting metadata from plugin failed with error: 'unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested. '

parthea commented 3 years ago

Hi @Greta991 ,

Please could you try the latest release 0.4.3, which includes auth changes, and let me know if the issue still exists?

parthea commented 3 years ago

Hi @Greta991 ,

I'm going to close this issue due to inactivity but if the issue still exists please feel free to re-open this issue.

Greta991 commented 3 years ago

I'm sorry to reply so late. I found the problem. I was using an email in delegated_credentials that was not part of my organization. Thank you.