首页 文章

完整的日历,活动假期和自己的活动

提问于
浏览
0

我想混合我自己的事件,并从谷歌日历中检索给定国家/地区的假期 . 我有我的API密钥等 . 我从ajax调用获取数据,并将我的事件构建为

my_events.push({title:name,
                start: moment(date_begin),
                end:moment(date_end)
          });

工作得很好 . 现在我想要假期 . 在github中完整日历的演示中,我看到以下代码:

googleCalendarApiKey: 'xxx',
     // US Holidays
     events: 'usa__en@holiday.calendar.google.com',

它的工作原理(当然是用我自己的密钥) .

但现在,我无法理解如何同时看到my_events和假期 . 我试过my_events.push({'usa__en@holiday.calendar.google.com'})不起作用 .

我怎么做 ?

另一个问题是,我不在美国,我想让欧洲国家度假 . 有人知道法国,意大利等地区是否有相似的地址?我试过fr,fra__fr,it,ita__it等但总是得到一个“notFound”

感谢任何指针和解释

1 回答

  • 0

    您可以使用fullcalendar添加多个事件源 - 拥有您的事件源,然后为假日日历添加一个

    这是下面代码的小提琴(你必须有一个API密钥!)https://jsfiddle.net/5x2dL5Ls/

    /* Modified from http://fullcalendar.io/js/fullcalendar-2.6.0/demos/gcal.html */
    
    $('#calendar').fullCalendar({
    
      // THIS KEY WON'T WORK IN PRODUCTION!!!
      // To make your own Google API key, follow the directions here:
      // http://fullcalendar.io/docs/google_calendar/
      googleCalendarApiKey: 'PUT_YOUR_API_KEY_HERE',
    
    /* For demo purposes, our hard-coded event source information */
      defaultDay: '2016-02-01',
      events: [{
        title: 'This is a non-google-holiday event',
        start: '2016-02-16',
        end:   '2016-02-20'
      }],
    /* For demo purposes */
    
      eventClick: function(event) {
        // opens events in a popup window
        window.open(event.url, 'gcalevent', 'width=700,height=600');
        return false;
      },
    
      loading: function(bool) {
        $('#loading').toggle(bool);
      }
    
    });
    
    $('#addSource').click(function() {
      var source = $('#holidayCalendar').val();
      // $('#calendar').fullCalendar('removeEventSource', source);
      $('#calendar').fullCalendar('addEventSource', source);
    });
    
    $('#removeSource').click(function() {
      var source = $('#holidayCalendar').val();
      $('#calendar').fullCalendar('removeEventSource', source);
    });
    

    我没有找到完整的假日来源列表的好文档,所以我通过抓取calendar.google.com上的“浏览有趣的日历”链接中的数据来制作一个

    [/* ... */,    {
        "title":"Holidays in United States",
        "type":"calendar",
        "did":"ZW4udXNhI2hvbGlkYXlAZ3JvdXAudi5jYWxlbmRhci5nb29nbGUuY29t",
        "country":"US"
    }, /* ... */]
    

    然后将该数据中的“ did ”附加到此网址上,例如美国假期

    https://calendar.google.com/calendar/embed?src=ZW4udXNhI2hvbGlkYXlAZ3JvdXAudi5jYWxlbmRhci5nb29nbGUuY29t

    并抓取该页面的“cids”:{“the_creator_is_in_here”:并解压缩... Hackish,但得到了一份日历列表 .

    对于语言,您可以尝试更改“en” . 到另一种语言前缀 .

    例如,“日本假期”可以用英语或日语呈现:

    • en.japanese#holiday@group.v.calendar.google.com

    • ja.japanese#holiday@group.v.calendar.google.com

相关问题