Gmail标签请求失败,http 403(禁止)

时间:2016-02-05 18:50:54

标签: google-oauth gmail-api

我有一个使用OAuth 2访问Gmail的应用程序。这对大多数用户来说都很好。但是,对于某些用户,我的应用程序在尝试读取Gmail标签时失败,其中包含http错误403(禁止)。请记住,在此API调用之前,我已成功访问用户配置文件。这是失败的电话:

GET /gmail/v1/users/user.name@domain.com/labels?access_token=ya29.fwI_zL1rF3xOIQcHNzpBhmjVlJhRpofkh4a9mVvwhYRo6H09qX5RNKv76zKT7e6-sEZr

我在获取访问令牌时请求以下范围,并且用户已登录Google并接受访问请求(我们在查看其安全仪表板时可以看到这一点):

https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/userinfo.profile
https://www.google.com/m8/feeds
https://www.googleapis.com/auth/tasks
https://www.googleapis.com/auth/gmail.labels
https://mail.google.com/

请注意,我刚刚添加了gmail.labels范围,试图解决此问题。 同样,这段代码适用于大多数用户 - 为什么有些用户会失败标签请求?

1 个答案:

答案 0 :(得分:0)

使用速记值me代替user.name@domain.comaccess token所属的用户将自动使用。