import google.ads.google_ads.client
import google.oauth2.credentials
# Initialize Credentials using the credentials you received
# in the earlier steps.
credentials = google.oauth2.credentials.Credentials(
None,
refresh_token=refresh_token,
client_id=client_id,
client_secret=client_secret,
token_uri='https://accounts.google.com/o/oauth2/token')
# Initialize the GoogleAdsClient.
client = google.ads.google_ads.client.GoogleAdsClient(
credentials, developer_token)
(<_Rendezvous of RPC that terminated with: status = StatusCode.UNAUTHENTICATED details = "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project." debug_error_string = "{"created":"@1566x68633.012x11175","description":"Error received from peer ipv4:xxx.58.2x0.42:443","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}">, <_Rendezvous of RPC that terminated with: status = StatusCode.UNAUTHENTICATED details = "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project." debug_error_string = "{"created":"@1x68633.01x1175","description":"Error received from peer ipv4:216.x8.20x.42:443","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}">, errors { error_code { authentication_error: AUTHENTICATION_ERROR } message: "Authentication of the request failed."}, 'OpFCsUhrNjDtgSRAT-N2YA')
Hi Jia,
Thank you for reaching support. With regards to your concern, it looks like you have sent invalid authentication credentials while making call to API. This is the reason you are getting StatusCode.UNAUTHENTICATED error. Could you please verify if the correct credentials are used while making API call. You might find our Quickstart guide useful for the process of acquiring the correct set of credentials needed to make call to the API. Let us know if you are still facing issue.
Regards,
Nikisha Patel, Google Ads API Team
# refresh_token Got in earlier steps
# client_id from settings file
# client_secret from settings file
# do not need access_token, for with refresh_token access_token will automaticly generated
credentials = google.oauth2.credentials.Credentials(
None,
refresh_token=refresh_token,
client_id=client_id,
client_secret=client_secret,
token_uri='https://accounts.google.com/o/oauth2/token')
# Initialize the GoogleAdsClient.
client = google.ads.google_ads.client.GoogleAdsClient(
credentials, developer_token)
# 1) got specified credentials
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
CLIENT_SECRETS_FILE, scopes=SCOPES, state=state)
flow.redirect_uri = REDIRECT_URL
authorization_response = REQUEST_URL
flow.fetch_token(authorization_response=authorization_response)
# Store credentials
credentials = flow.credentials
# the credentials is like
credentials_dict = \
{'token': 'xITMxxQCxxxx8wM3VIeG0',
'client_secret': 'L3xd7ioxD',
'scopes': ['https://www.googleapis.com/auth/adwords'],
'refresh_token': 'xcZoxxxxxxxxx8',
'token_uri': 'https://oauth2.googleapis.com/token',
'client_id': '7xogleuserconxxt.coxm'}
...
# 2) got an adsclient using credentials
credentials = google.oauth2.credentials.Credentials(credentials)
adsclient = google.ads.google_ads.client.GoogleAdsClient(
credentials, developer_token)
# 3) do different service by client
customer_service = adsclient.get_service('CustomerService', version='v2')
customers = customer_service.list_accessible_customers()
print(customers)
google.ads.google_ads.errors.GoogleAdsException: (<_Rendezvous of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
debug_error_string = "{"created":"@1566544852.226886110","description":"Error received from peer ipv4:17d.1d:443","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"
>, <_Rendezvous of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
debug_error_string = "{"created":"@1566544852.226886110","description":"Error received from peer ipv4:1dd:4d3","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"
>, errors {
error_code {
authentication_error: AUTHENTICATION_ERROR
}
message: "Authentication of the request failed."
}
, 'IOPV3IUx7wLHzHQbbEH6WQ')
Hi Jia,
ref:_00D1U1174p._5001UHEN2K:ref
Hi Jia,
Could you please verify your credentials by using the OAuth doctor? This tool will help you determine if your OAuth2 credentials are configured correctly, and if they are ready to make API calls. It will also guide you through fixing any OAuth2 problems it detects and verify the corrected configuration. Please give this a try and let us know if you have any issues.
Regards,
Nikisha Patel, Google Ads API Team