我用的是
gapi
googleUser.getAuthResponse().id_token
在JavaScript中通过OAuth2发送到服务器。然后我想使用Java API访问Gmail API以列出帐户上的消息,但在尝试访问它时出现以下错误:
[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] }
请原谅Scala代码,但我调用的是:
val gmail = new Gmail.Builder(transport, jsonFactory, credential)
.setApplicationName("myapp")
.build()
val response = gmail.users().messages().list(userId).execute()
这个
userId
我从javaapi的profile lookup(它工作得很好)得到消息,它只是试图访问
Gmail
给我带来麻烦的例子。我已经搜索过了,但是很难找到关于这个特定情况的任何信息。