AUTHENTICATION_ERROR when initialize a GoogleAdsClient

299 views
Skip to first unread message

jia Jimmy

unread,
Aug 22, 2019, 9:06:23 AM8/22/19
to AdWords API and Google Ads API Forum
As Setting up the client library suggested. I use codes below to initialize a client object and then do some service.


I've got  the refresh_token followed starting steps.

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)



But I always got error like :


(<_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')


What's the problem, and what should I do to make it work as expected..


Google Ads API Forum Advisor Prod

unread,
Aug 22, 2019, 4:51:26 PM8/22/19
to 5424...@qq.com, adwor...@googlegroups.com

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



ref:_00D1U1174p._5001UHEN2K:ref

jia Jimmy

unread,
Aug 23, 2019, 3:18:02 AM8/23/19
to AdWords API and Google Ads API Forum
Thanks for your replying, Nikisha. What I'm confused is  that I can get a credentials object with refresh_token in the earlier steps, for refresh_token will automaticly generate access_token, then I could initialize a client onject. Am I right?
# 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)




在 2019年8月23日星期五 UTC+8上午4:51:26,adsapiforumadvisor写道:

jia Jimmy

unread,
Aug 23, 2019, 4:00:49 AM8/23/19
to AdWords API and Google Ads API Forum
After followed Quickstart guide, I'm still meeting the same error, here's my trial:
# 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)


same error happend when tring to list all 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')


Can you help me about my problem?


在 2019年8月23日星期五 UTC+8上午4:51:26,adsapiforumadvisor写道:

Hi Jia,



ref:_00D1U1174p._5001UHEN2K:ref

Google Ads API Forum Advisor Prod

unread,
Aug 23, 2019, 10:36:15 AM8/23/19
to 5424...@qq.com, adwor...@googlegroups.com

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



ref:_00D1U1174p._5001UHEN2K:ref
Reply all
Reply to author
Forward
0 new messages