简体   繁体   English

如何在公共网站上提取 Google 日历事件?

[英]How to pull Google Calendar events on a public website?

I'm in the process of building a website and want to include a component that lists the three next upcoming calendar events from a public Google Calendar.我正在构建一个网站,并希望包含一个组件,该组件列出了来自公共 Google 日历的三个即将到来的日历事件。 I'm building the site using GatsbyJS, and so will be using Node.js to process the data and display it correctly on the page.我正在使用 GatsbyJS 构建站点,因此将使用 Node.js 来处理数据并在页面上正确显示它。 What I'm not quite sure how to do, however, is interface with the Google Calendar API in the first place;然而,我不太确定该怎么做,首先是与 Google Calendar API 的接口; I'm building a static site with no backend, so will need to interact with the API clientside instead.我正在构建一个没有后端的静态站点,因此需要与 API 客户端进行交互。

I've done a bit of reading and found the documentation for Googles Node.js Client .我做了一些阅读并找到了Googles Node.js Client文档 It lists three different ways of interacting with the API but I'm not sure which is more appropriate for my situation?它列出了与 API 交互的三种不同方式,但我不确定哪种方式更适合我的情况? I think I've rules out OAuth2 since it sounds like individual users would need to sign in with their Google accounts in order for the calendar event pulling to work correctly (which is hardly a good solution).我想我已经排除了 OAuth2,因为听起来个人用户需要使用他们的 Google 帐户登录才能使日历事件正常工作(这不是一个好的解决方案)。 Which of the other two options do you think I should be using?您认为我应该使用另外两个选项中的哪一个?

Also, are there any security concerns I should be taking into account, given it's likely the website might be storing API keys and/or client IDs in a publicly accessible way?另外,考虑到网站可能以可公开访问的方式存储 API 密钥和/或客户端 ID,我是否应该考虑任何安全问题?

The API key method stores your API key and is no different than including it in plaintext in the query string when loading eg API 密钥方法存储您的API 密钥,与加载时将其以纯文本形式包含在查询字符串中没有什么不同,例如

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>

When you create the key, you can then restrict its usage to certain HTTP referers etc.创建密钥时,您可以将其使用限制为某些 HTTP 引用等。

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

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