Google Ads API "RefreshError: ('unauthorized_client: Unauthorized', {'error': 'unauthorized_client', 'error_description': 'Unauthorized'})"
I am trying to make a call to Google Ads API to access campaign data in python. I have completed the following steps:
- Created a web app and enabled Google-Ads API
- Saved JSON file that contains client id and secret information
- Generated refresh token
- Updated google-ads yaml file based on the client id, client secret, refresh token, developer token and customer id
However when I try this:
from google.ads.googleads.client import GoogleAdsClient client = GoogleAdsClient.load_from_storage("google-ads.yaml")
I get the error:
RefreshError: ('unauthorized_client')
I have rechecked for any typos or white-spaces. I have the "Standard Access" on my email id: on Google-Ads account under the Access and Security section. Any help would be really great.
You need to generate your refresh token again.
Is your app set to testing/public? Are you an added as an authorised user for if it's testing?
i was encountering the same error but i was testing the api from that gamil account that was not added in the testing..... The one you are using/testing the api you should add that email into testing area of google api....
Go to the OAuth2 Playground, (using this link should pre-populate some key values for you).
Click the gear icon in the upper right corner and check the box labeled Use your own OAuth credentials (if it isn't already checked).
Make sure that:
OAuth flow is set to Server-side. Access type is set to Offline (this ensures you get a refresh token and an access token, instead of just an access token). Enter the OAuth2 client ID and OAuth2 client secret you obtained above.
In the section labeled Step 1 - Select & authorize APIs, click Google Ads API from the list and select its scope, https://www.googleapis.com/auth/adwords. Then click Authorize APIs:
authorize apis
If prompted, sign in to the account to which you want to grant access and authorization. Otherwise, confirm that the current Google user in the top right corner is the Google Ads or manager account for whom you want to obtain credentials.