如何获取访问Gmail的OAuth权限?

11
如何获得用户发起的访问以读取其电子邮件?似乎有OpenID、OAuth、OAuth2和其他随机解决方案。
到目前为止,我想到的最好的方法是使用scope=https://mail.google.com/的OAuth2。
是否有任何权限只能给我只读访问邮件,并且最好不会显示像这样的权限通知吓唬用户:
"查看和管理您的邮件 在我不使用该应用程序时执行这些操作"
如果可能的话,我只需要"查看您的邮件"。
2个回答

12

之前的答案已不再准确。最近发布的Gmail API允许使用“只读”范围等其他范围,请在此处找到:https://developers.google.com/gmail/api/auth/scopes

“只读”范围是:https://www.googleapis.com/auth/gmail.readonly

https://www.googleapis.com/auth/gmail.readonly
Read all resources and their metadata—no write operations.

https://www.googleapis.com/auth/gmail.compose
Create, read, update, and delete drafts. Send messages and drafts.

https://www.googleapis.com/auth/gmail.send
Send messages only. No read or modify privileges on mailbox.

https://www.googleapis.com/auth/gmail.insert
Insert and import messages only.

https://www.googleapis.com/auth/gmail.labels
Create, read, update, and delete labels only.

https://www.googleapis.com/auth/gmail.modify
All read/write operations except immediate, permanent deletion of threads and messages, bypassing Trash.

https://www.googleapis.com/auth/gmail.metadata
Read resources metadata including labels, history records, and email message headers, but not the message body or attachments.

https://www.googleapis.com/auth/gmail.settings.basic
Manage basic mail settings.

https://www.googleapis.com/auth/gmail.settings.sharing
Manage sensitive mail settings, including forwarding rules and aliases. 

Note: Operations guarded by this scope are restricted to administrative use only. They are only available to G Suite customers using a service account with domain-wide delegation. 

https://mail.google.com/
Full access to the account, including permanent deletion of threads and messages. This scope should only be requested if your application needs to immediately and permanently delete threads and messages, bypassing Trash; all other actions can be performed with less permissive scopes.

1
在你的回答中发布链接对于用户想要进一步阅读是很好的,但你也应该在回答中总结链接内容。如果链接失效,你的回答仍然需要有用。 - skrrgwasme
3
这篇文章要求 Gmail API 的“只读”范围。我已经单独提供了该范围,并提供了所有其他范围的链接。碰巧这篇文章所要求的是一个 HTTPS 链接。 - artis3n
感谢您的更新答案。只是一个问题:您知道如何在我的应用程序获得用户权限后实际获取电子邮件吗? - kramer65
“https://www.googleapis.com/auth/gmail.send” 返回的令牌无法与 MailMan 兼容。 - Andrew Truckle

4

GMail API文档指出,只有一个作用域可以访问所有内容。

此外,还有一个名为GMail Inbox Feed的功能,可能是您需要的,但它仅适用于Google应用程序域。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接