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

时间:2015-06-14 19:53:27

标签: javascript google-api google-calendar-api

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

可能吗?我该怎么做?

2 个答案:

答案 0 :(得分:10)

是的,使用google api可以做到这一点。

  • 在Google开发者帐户中创建API应用 。https://console.developers.google.com
  • 来自"凭证"您可以使用Tab键创建API密钥 这样的事情" AIzaSyBcOT_DpEQysiwFmmmZXupKpnrOdJYAhhM"
  • 然后您可以使用此网址
  • 访问假日日历

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

答案 1 :(得分:2)

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",