从 Google 日历 API 获取国家/地区的假期列表

Get Holidays List of a Country from Google Calendar API

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

可能吗?我该怎么做?

是的,使用 Google API 你可以做到。

  • google developer account

    中创建一个 API 应用程序
  • 从“凭据”选项卡中,您可以创建一个 API 密钥,您将获得 像这样 AIzaSyBcOT_DpEQysiwFmmmZXupKpnrOdJYAhhM

  • 然后,您可以使用 this URL

    访问假期日历

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#holiday@group.v.calendar.google.com",
    "displayName": "Holidays in United States",
    "self": true
   },
   "organizer": {
    "email": "en.usa#holiday@group.v.calendar.google.com",
    "displayName": "Holidays in United States",
    "self": true
   },
   "start": {
    "date": "2020-01-01"
   },
   "end": {
    "date": "2020-01-02"
   },
   "transparency": "transparent",
   "visibility": "public",
   "iCalUID": "20200101_60o30dr46oo30c1g60o30dr56g@google.com",
   "sequence": 0
  },
  {
.........

我们将在其中获取所有详细信息,例如, “摘要”键中的假日名称

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