从谷歌日历API获取一个国家的假期列表

Get Holidays List of a Country from Google Calendar API

本文关键字:一个 国家 列表 假期 日历 谷歌 API 获取      更新时间:2023-09-26

我想使用 JavaScript 从 Google 日历 API 中提取某个国家的假期列表。

可能吗?我该怎么做?

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

  • 在谷歌开发者帐号中创建 API 应用

  • 从"凭据"选项卡中,您可以创建API密钥,您可以获得像这样的东西AIzaSyBcOT_DpEQysiwFmmmZXupKpnrOdJYAhhM

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

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

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": [
  {
   "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",