【问题标题】:Get Holidays List of a Country from Google Calendar API从 Google Calendar API 获取国家/地区的假期列表
【发布时间】:2015-08-30 06:43:32
【问题描述】:

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

有可能吗?我该怎么做?

【问题讨论】:

  • 我不相信谷歌会在任何 API 中保存不同国家/地区的假期列表。不过,您可以找到带有特定国家/地区假期的公共日历。

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


【解决方案1】:

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

  • 在 google 开发者账号中创建 API 应用 .https://console.developers.google.com
  • 从“凭据”选项卡中,您可以创建一个 API 密钥,您将获得 像这样的“AIzaSyBcOT_DpEQysiwFmmmZXupKpnrOdJYAhhM”
  • 然后您可以使用此网址访问节假日日历

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

【讨论】:

  • 如何获取其他国家的日历列表??
  • 嗨@Midhun1993,我遵循了你的方法。但我一直看到“需要登录”消息。请帮忙指教:drive.google.com/file/d/1wQ8FZPTzDXpZxvDAKNiUDKHqJeniynhd/…
  • 嗨@BorgyManotoy 我认为:restcountries.eu 会帮助你。请检查
  • 感谢 Midhun1993,但我认为我需要可以在 api 中使用的国家/地区列表(在您的答案中)。目前使用usuksingaporechinaindianphilippinesspain 对其进行了测试...但仍有很多国家我想使用但不要使用不知道要在 API 调用中提供的值。这就是为什么我想获取可以在调用此 API 时使用的国家/地区列表(代码)。谢谢
  • 这适用于国家/地区。目前 API 返回指定国家/地区的 3 年假期 past one yearcurrent yearfuture year。有没有办法获得过去或未来的特定年份?
【解决方案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",

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 2012-11-21
    • 2013-03-09
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多