Gmail API返回403错误代码和“拒绝<用户电子邮件"的授权.

问题描述:

使用以下错误检索邮件时,Gmail API在一个域中失败:

Gmail API fails for one domain when retrieving messages with this error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 OK
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Delegation denied for <user email>",
    "reason" : "forbidden"
  } ],
  "message" : "Delegation denied for <user email>"
}

我正在使用OAuth 2.0和Google Apps Domain-Wide授权来访问用户数据.该域已授予该应用程序数据访问权限.

I am using OAuth 2.0 and Google Apps Domain-Wide delegation of authority to access the user data. The domain has granted data access rights to the application.

似乎最好的做法是始终在您的请求中使用userId ="me".这告诉API仅使用经过身份验证的用户的邮箱-无需依赖电子邮件地址.

Seems like best thing to do is to just always have userId="me" in your requests. That tells the API to just use the authenticated user's mailbox--no need to rely on email addresses.