通过Flutter中的服务帐户访问Google日历API | nodejs
在Google api docs ,提到,唯一的授权请求的方法是是通过oauth2.0。
但是,我不需要访问用户的日历,我想在日历中创建一个事件,并添加用户作为与会者。我需要邀请来从xyz.com
出去 由于这是我拥有的帐户,因此我认为应该有一种通过服务帐户访问它的方法。 我理解最好的方法是编写我的网站前端调用的后端功能。
有一些帮助清除。
当我与人A和人b创建活动时,
这就是今天的样子 -
- 请求从个人访问事件的
- 事件A的日历,并添加个人B作为与会者,
这就是我希望的 -
- 事件 -事件在我的日历中创建(服务帐户拥有)
- A和人B作为与会者
In the Google API docs, it is mentioned that the only way to authorize requests is through OAuth2.0.
However I do not need to access user's calendar, I want to create an event in my calendar and add users as Attendee. I need the invites to go out from xyz.com
Since this is an account I'd own, I feel there should be a way to access it though a service account.
I understand the best way to do this is to write a backend function that is called by my website front-end.
There is some help here, but it is not clear.
When I am creating an event with Person A and Person B
This is how it is today -
- Request Access to event from Person A
- Event gets created in Person A's calendar and Person B is added as attendee
This is how I want it to be -
- Event gets created in my calendar (owned by a service account)
- Person A and Person B are added to it as attendee
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一个Google Workspace帐户,这是您要访问的Google Workspace日历。然后,您可以使用服务帐户。
使用服务帐户授权将不需要任何用户交互。但是,需要为
服务帐户将无法与标准Gmail用户Google Calendar帐户一起使用。如果是这种情况,那么您应该只使用OAuth2并授权您的应用程序一次并存储刷新令牌。然后,您的应用程序可以使用刷新令牌在以后访问您的帐户。
If you have a google workspace account, and this is a google workspace calendar you are trying to access. Then you could use a service account.
using service account authorization will not require any user interaction. However service account will need to be configured for domain wide delegation in your google workspace account by a workspace admin. Tip if you check that link swap out the scopes with the scope for google calendar.
Service accounts will not work with standard gmail user google calendar accounts. If this is the case then you should just use Oauth2 and authorize your app once and store the refresh token. your app can then use the refresh token to access your account at a later date.
您可以使用一个服务帐户,但需要在前端公开您的client_is和client_secret。使用服务帐户称为client_credentials流。它通常在后端使用,因为它是用于服务器身份验证/授权的服务器。在后端使用客户秘密是安全的。
在您的情况下,您必须使用授权代码流。这不是那么征税。这意味着您必须通过自己的所有者(服务帐户的所有者)来获取服务帐户的令牌。然后,您可以自己创建事件(您确实应用程序)并邀请A和B。
You can use a service account but it requires exposing your client_is and client_secret in the front end. Using service account is called client_credentials flow. It is typically used on the backend because it is meant for server to server authentication/authorization. It is safe to use client secret on the backend.
In your case you have to use authorization code flow. It is not that taxing. This means that you have to obtain a token for your service account by logging in as yourself, the owner of the service account. Then you can create the event for yourself (you app really) and invite Person A and B.