I'm using the gapi to get googleUser.getAuthResponse().id_token in JavaScript via OAuth2 that I send to my server. I then want to use the Java API to access the Gmail API to list the messages on the account, but I'm getting the following error when I try 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] }
Forgive the Scala code, but this is what I'm invoking:
val gmail = new Gmail.Builder(transport, jsonFactory, credential)
.setApplicationName("myapp")
.build()
val response = gmail.users().messages().list(userId).execute()
The userId I'm getting from the Java API's profile lookup (which works great), it's just trying to access the Gmail instance that is giving me trouble. I've searched but am having a hard time finding any information on this specific situation.