AuthenticationError.OAUTH_TOKEN_INVALID

170 views
Skip to first unread message

nikhil almeida

unread,
Sep 28, 2018, 4:12:36 PM9/28/18
to AdWords API and Google Ads API Forum
I have tried configuring the yaml file and getting the constructor by loading from storage while also the method below.
But I keep getting the following error. Can some one please help?

[2018-09-27 17:02:52,326 - googleads.soap - WARNING] Error summary: {'faultMessage': "[AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>']", 'requestId': '000576e32d3d31000aa37e521e0075d1', 'serviceName': 'CustomerService', 'methodName': 'getCustomers', 'operations': '0', 'responseTime': '20'}

....

GoogleAdsServerFault
: [AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>'] 




# OAuth2 credential information.
DEFAULT_CLIENT_ID = 'INSERT_CLIENT_ID_HERE'
DEFAULT_CLIENT_SECRET = 'INSERT_CLIENT_SECRET_HERE'
DEFAULT_REFRESH_TOKEN = 'INSERT_REFRESH_TOKEN_HERE'
# AdWords API information.
DEFAULT_CLIENT_CUSTOMER_ID = 'INSERT_CLIENT_CUSTOMER_ID_HERE'
DEFAULT_DEVELOPER_TOKEN = 'INSERT_DEVELOPER_TOKEN_HERE'
USER_AGENT = 'INSERT_USER_AGENT_HERE'

oauth2credentials = client.OAuth2Credentials(
      None, DEFAULT_CLIENT_ID, DEFAULT_CLIENT_SECRET, DEFAULT_REFRESH_TOKEN,
      datetime.datetime(1980, 1, 1, 12), GOOGLE_OAUTH2_ENDPOINT,
      USER_AGENT)

oauth2credentials.refresh(httplib2.Http())

oauth2_client = oauth2.GoogleAccessTokenClient(oauth2credentials.access_token, oauth2credentials.token_expiry)


adwords_client = adwords.AdWordsClient(
  DEFAULT_DEVELOPER_TOKEN, oauth2_client, USER_AGENT,
  client_customer_id=DEFAULT_CLIENT_CUSTOMER_ID)

customer = adwords_client.GetService('CustomerService').getCustomers()[0]
print(f"You are logged in as {customer['customerId']}")

Dannison Yao (AdWords API Team)

unread,
Sep 30, 2018, 11:45:55 PM9/30/18
to AdWords API and Google Ads API Forum
Hi Nikhil,

My apologies for the delayed response. To answer your concern in this thread, if you are making calls against your production account, then yes, the OAuth2 Credentials has to be setup by the same email used in your production MCC account. 

Based on your logs, it seems that the credentials are not detected by the API. Could you confirm if you have inputted your OAuth2 Credentials and other information in the yaml file? If not, kindly input the credentials in their respective fields in the yaml file then you may try to call the service again.

If this still does not work, could you provide the complete SOAP request and response logs that were generated so that I could investigate this further? You may provide complete the logs via Reply privately to author.

Regards,
Dannison
AdWords API Team

Michael Cloonan (AdWords API Team)

unread,
Oct 1, 2018, 8:56:06 AM10/1/18
to AdWords API and Google Ads API Forum
Hello,

The best way to debug this kind of issue is to actually capture the network traffic or log the HTTP headers as you're making the call, to see whether or not you're actually successfully creating an access token. In the code you provided, you're using a non-recommended method of handling authentication. The Python client library can handle authentication for you, if you put your client id, client secret, and refresh token in a yaml file with standard format and just allow the client to read it. Alternatively, you can pass them to the client on initialization as a yaml string if you don't want to commit it to disk. See this example file: https://github.com/googleads/googleads-python-lib/blob/master/googleads.yaml

If you must pass your own oauth2 credentials to the class constructor, it must be a googleads.oauth2.GoogleOAuth2Client, which is another class that is part of the Python client library. I can't see the context in your code to see if you're using the right class or not, but I believe this may be the root cause of the issue.

Overall, I recommend doing your authentication by simply filling out the .yaml file and putting it in your home directory, and let the client library handle the implementation details.

Regards,
Mike, AdWords API Team

nikhil almeida

unread,
Oct 1, 2018, 6:20:50 PM10/1/18
to AdWords API and Google Ads API Forum
Hi, I did send the logs, code and credentials in a private message.
Thanks Nikhil

nikhil almeida

unread,
Oct 1, 2018, 6:21:04 PM10/1/18
to AdWords API and Google Ads API Forum
Hi, I did send the logs, code and credentials in a private message.
Thanks Nikhil

Reply all
Reply to author
Forward
0 new messages