TokenResponseException: 401 Unauthorized Exception when trying to access Admin SDK Google API.

后端 未结 4 718
遇见更好的自我
遇见更好的自我 2021-01-24 05:34

I am trying to do an extract of users in my domain by accessing the Google Admin SDK API. I am however given a 401 unauthorized exception. The code below is my settings class th

相关标签:
4条回答
  • 2021-01-24 06:00

    Based from this thread, TokenResponseException: 401 Unauthorized occurs when having an invalid client ID, client secret or scopes. But it could also be due to refresh token overuse. Refresh the access token, if necessary since it have limited lifetimes. If your application needs access to a Google API beyond the lifetime of a single access token, it can obtain a refresh token. A refresh token allows your application to obtain new access tokens.

    Check these related threads:

    • Java Google Contacts API Access Service Account Authentication which states that another possible source for a "401 Unauthorized" exception is leaving the credential.refreshToken() away. The call is necessary to write the access-code into the reference.
    • Always get TokenResponseException: 401 Unauthorized.

    Hope this helps!

    0 讨论(0)
  • 2021-01-24 06:02

    try deleting .credential directory - which is created in your local machine. this works.

    0 讨论(0)
  • 2021-01-24 06:11

    In my case in Intellij IDE, it cashed the credential file which was the issue. So if you are changing the google account and credential file you must also delete the cashed credentials. It is located in your project directory under token/StoredCredential

    0 讨论(0)
  • 2021-01-24 06:18

    I was running into this same issue when trying to use the Admin SDK Google API with a service account.

    The issue was occurring for me because the Scopes that were set in my code did not match those set at my Google Admin Console under "Security > Advanced Settings > Manage API client access". Once these were aligned it all started working perfectly.

    You also are required to have Domain Wide Delegation on for your service account? (This can be done here)

    0 讨论(0)
提交回复
热议问题