简体   繁体   English

谷歌日历 API 和 API 关键问题

[英]Google Calendar API and API Key issues

OK.好的。 So I am building a simple app for a friend.所以我正在为朋友构建一个简单的应用程序。 The biggest requirement for this app is that he wants a user to be able to go to his site and create an event on his google calendar.这个应用程序的最大要求是他希望用户能够通过 go 访问他的网站并在他的谷歌日历上创建一个活动。 I have let him know that this calendar will have to be made public and he is fine with that.我已经让他知道这个日历必须公开,他对此没有意见。 I created an API Key with google and the first call against the API with the API Key to get calendar events for a given day works fine.我用谷歌创建了一个 API 密钥,并且第一次调用 API 与 API 密钥以获取给定日期的日历事件工作正常。 The second request, a post, returns:第二个请求,一个帖子,返回:

err(401)"API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal."错误(401)“此 API 不支持 API 密钥。预期的 OAuth2 访问令牌或声明主体的其他身份验证凭据。”

It doesn't make sense that his website would be an OAuth app because that would require the user have a gmail account.他的网站是 OAuth 应用程序是没有意义的,因为这将要求用户拥有 gmail 帐户。

There has got to be some kind of way to make this work...必须有某种方法来使这项工作......

Thanks Everyone谢谢大家

I just want to make a post request to Google Calendar API using an API Key.我只想使用 API 密钥向 Google 日历 API 发出发布请求。

API keys only give read access. API 密钥仅提供读取权限。 If you want write access you need the permission of the owner of the calendar如果您想要写访问权,则需要日历所有者的许可

options选项

  1. Create a google workspace account and use a service account with domain wide deligation创建一个 google workspace 帐户并使用具有域范围授权的服务帐户
  2. use Oauth2 have your friend auth it once store the refresh token and use the refresh token to request a new access token when ever you want to write to the calendar使用 Oauth2 让你的朋友验证它一旦存储刷新令牌并使用刷新令牌在你想要写入日历时请求新的访问令牌

neither option will work with client side JavaScript switch to a server side programming language这两个选项都不适用于客户端 JavaScript 切换到服务器端编程语言

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM