且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过GMail API进行用户模拟的服务器端OAuth

更新时间:2023-12-04 15:55:40

据我所知,您不能在Gmail中使用服务帐户.服务帐户必须是预先授权的.

As far as I know you cant use a service account with Gmail. Service accounts must be pre authorized.

使用Gmail授权应用

所有对Gmail API的请求必须由经过身份验证的用户授权 用户. Gmail使用 OAuth 2.0 协议对Google进行身份验证 帐户并授权访问用户数据.您也可以使用Google+ 登录以提供使用Google登录"身份验证方法 您的应用.

All requests to the Gmail API must be authorized by an authenticated user. Gmail uses the OAuth 2.0 protocol for authenticating a Google account and authorizing access to user data. You can also use Google+ Sign-in to provide a "sign-in with Google" authentication method for your app.

  1. 与服务"帐户共享一个Google驱动器文件夹.以用户身份将服务帐户电子邮件添加到具有访问权限的google驱动器文件夹中
  2. 与其他用户一样,与服务帐户共享Google日历.

服务帐户无法在所有Google API上使用.据我所知,您无法授予其他用户访问您的Gmail的权限,因此现在可以对服务帐户进行预授权了.

Service accounts don't work on all Google APIs. To my knowledge you cant give another user access to your Gmail so there will be now to pre authorize the service account.

推荐/解决方法/破解

使用相同的客户端ID创建一个虚拟应用,对其进行身份验证以获取刷新令牌,然后在您的应用中使用刷新令牌.

Create a dummy app using the same client id, authenticate it get the refresh token then use the refresh token in your application.