Utilizing the gapi
in JavaScript via OAuth2 to retrieve
googleUser.getAuthResponse().id_token
, which I then send to my server. My goal is to utilize the Java API to interact with the Gmail API and list messages on the account. However, I'm encountering the following error when attempting to access it:
[error] com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
[error] {
[error] "code" : 401,
[error] "errors" : [ {
[error] "domain" : "global",
[error] "location" : "Authorization",
[error] "locationType" : "header",
[error] "message" : "Invalid Credentials",
[error] "reason" : "authError"
[error] } ],
[error] "message" : "Invalid Credentials"
[error] }
Apologies for the Scala code snippet, but here is the implementation I'm using:
val gmail = new Gmail.Builder(transport, jsonFactory, credential)
.setApplicationName("myapp")
.build()
val response = gmail.users().messages().list(userId).execute()
The userId
is obtained successfully from the Java API's profile lookup, but accessing the Gmail
instance is where the issue arises. Despite searching extensively, I have not found a solution tailored to this particular scenario.