简体   繁体   English

服务帐户的oauth2

[英]oauth2 for service account

I want to have a Google API Script deployed as a web app. 我想将Google API脚本部署为网络应用。 I understand how to do that. 我知道该怎么做。

I want this script to list and add events on a Google Calendar. 我希望此脚本列出并在Google日历上添加事件。 I have plenty of documentation and examples to do that. 我有很多文档和示例可以做到这一点。

I want this script to read a calendar using a service account. 我希望此脚本使用服务帐户读取日历。 I have already created the service account and shared the calendar with it. 我已经创建了服务帐户并与它共享日历。

The end goal is to have a Javascript client access this script, use it to retrieve a list of events on the calendar and use it to create events on it. 最终目标是让Javascript客户端访问此脚本,使用它来检索日历上的事件列表,并使用它在日历上创建事件。

What I don't understand is how to authenticate a service account. 我不了解如何验证服务帐户。 I keep seeing code like: 我一直看到类似的代码:

oauthConfig.setConsumerKey("anonymous"); oauthConfig.setConsumerKey(“ anonymous”); oauthConfig.setConsumerSecret("anonymous"); oauthConfig.setConsumerSecret(“ anonymous”); oauthConfig.setRequestTokenUrl( " https://www.google.com/accounts/OAuthGetRequestToken?scope= "+scope); oauthConfig.setRequestTokenUrl(“ https://www.google.com/accounts/OAuthGetRequestToken?scope= ” + scope); oauthConfig.setAuthorizationUrl(" https://accounts.google.com/OAuthAuthorizeToken "); oauthConfig.setAuthorizationUrl(“ https://accounts.google.com/OAuthAuthorizeToken ”); oauthConfig.setAccessTokenUrl(" https://www.google.com/accounts/OAuthGetAccessToken "); oauthConfig.setAccessTokenUrl(“ https://www.google.com/accounts/OAuthGetAccessToken ”);

How do I modify this to use a service account? 如何修改它以使用服务帐户? I do not understand if/how I pass in the service account client id/email address. 我不知道是否/如何传递服务帐户客户ID /电子邮件地址。 I also am unclear how to pass in the public/private keys. 我也不清楚如何传递公钥/私钥。

Can anyone help? 有人可以帮忙吗?

The Drive API documentation has a really good example on how to use service account. Drive API文档中有一个很好的有关如何使用服务帐户的示例。 It has steps by steps on how to create a service account, and it also includes multiple code samples. 它分步介绍了如何创建服务帐户,并且还包含多个代码示例。 The only thing is you would have to change the scope to Calendar API from Drive API. 唯一的事情是您必须将驱动器API的范围更改为Calendar API。

https://developers.google.com/drive/web/delegation https://developers.google.com/drive/web/delegation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有服务帐户的Google协调中心OAuth2 - Google Coordinate OAuth2 with Service Account 如何使OAuth2与服务帐户一起使用 - How to get OAuth2 working with a service account Nodejs 发布请求以获取服务帐户的 oauth2 令牌 - Nodejs post request to get oauth2 token for a service account 带有Google Speech API RPC服务帐户的Google Oauth2无法正常工作 - Google Oauth2 with Service account for Google Speech API rpc not working 带有服务帐户的Google OAuth2 - 指定要代表的用户电子邮件 - Google OAuth2 with Service Account - specifying the user email to act on behalf of Google API OAuth2,服务帐户,“错误”:“invalid_grant” - Google API OAuth2, Service Account, “error” : “invalid_grant” 将Google EmailSettings API python代码从OAuth1移至OAuth2服务帐户 - Move Google EmailSettings API python code from OAuth1 to OAuth2 service account 如何使用Javascript从Google Api检索服务帐户OAuth2令牌? - How can I retrieve a service account OAuth2 token from Google Api with Javascript? Google API OAuth2:使用Perl请求服务帐户令牌时出现“ invalid_grant”错误 - Google API OAuth2 : “invalid_grant” error when requesting token for Service Account with Perl 通过服务器端的服务帐户使用 gmail api 避免 OAUTH2 GUI - Make use of the gmail api through a service account from the server side avoiding the OAUTH2 GUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM