从 Google Calendar API 获取一个国家/地区的假期列表

问题描述 投票:0回答:3

我想使用 JavaScript 从 Google Calendar API 中提取某些国家/地区的假期列表。

有可能吗?我怎样才能做到这一点?

javascript google-api google-calendar-api
3个回答
38
投票

是的,使用 Google API 您可以做到这一点。

  • google 开发者帐户中创建 API 应用程序

  • 从“Credentials”选项卡中,您可以创建一个 API 密钥,您将获得 像这样的东西

    AIzaSyBcOT_DpEQysiwFmmmZXupKpnrOdJYAhhM

  • 然后,您可以使用此 URL 访问假期日历

    https://www.googleapis.com/calendar/v3/calendars/en.uk%23holiday%40group.v.calendar.google.com/events?key=<YOUR API KEY>


8
投票

google 提供假期列表 API。

https://www.googleapis.com/calendar/v3/calendars/en.uk%23holiday%40group.v.calendar.google.com/events?key=YourApiKey

  1. 就像我们想要美国的假期清单

然后,更改 url 中的文本

calendars/en.usa

示例:- https://www.googleapis.com/calendar/v3/calendars/en.usa%23holiday%40group.v.calendar.google.com/events?key=YourApiKey

在此之后,

  1. 我们在“items”数组中获取所有假期事件列表。

像这样

 "items": [
  {
   "kind": "calendar#event",
   "etag": "\"3101513576000000\"",
   "id": "20200101_60o30dr46oo30c1g60o30dr56g",
   "status": "confirmed",
   "htmlLink": "https://www.google.com/calendar/event?eid=MjAyMDAxMDFfNjBvMzBkcjQ2b28zMGMxZzYwbzMwZHI1NmcgZW4udXNhI2hvbGlkYXlAdg",
   "created": "2019-02-21T13:46:28.000Z",
   "updated": "2019-02-21T13:46:28.000Z",
   "summary": "New Year's Day",
   "creator": {
    "email": "en.usa#[email protected]",
    "displayName": "Holidays in United States",
    "self": true
   },
   "organizer": {
    "email": "en.usa#[email protected]",
    "displayName": "Holidays in United States",
    "self": true
   },
   "start": {
    "date": "2020-01-01"
   },
   "end": {
    "date": "2020-01-02"
   },
   "transparency": "transparent",
   "visibility": "public",
   "iCalUID": "[email protected]",
   "sequence": 0
  },
  {
.........

我们将在那里获得所有细节,例如, “摘要”键中的节日名称

"summary": "New Year's Day",

0
投票

https://gist.github.com/dhoeric/76bd1c15168ee0ee61ad3bf1730dcb65

这是所有国家/地区的列表。

需要更换

en.indian.official#[email protected]
在网址中。

https://www.googleapis.com/calendar/v3/calendars/**en.uk%23holiday%40group.v.calendar.google.com**/events?key=YourApiKey

突出显示的部分需要更换。 如果您收到身份验证错误,请更换

#
%23
@
%40

由于一些解析问题,它会带来身份验证问题。

© www.soinside.com 2019 - 2024. All rights reserved.