首页 文章

Google Calendar API将日期,时间和事件名称返回给Javascript

提问于
浏览
1

用Google的日历API将我的头撞在墙上 . 我的日历是公开的,地址为:

9p79sl2a31qgqfvjkfkupdbf8o@group.calendar.google.com

我希望将来访问最近的10个活动,并将他们的日期,时间和事件名称放在我的页面上 . 我试图访问如下:

var url = 'http://www.google.com/calendar/feeds/9p79sl2a31qgqfvjkfkupdbf8o@group.calendar.google.com/public/full?orderby=starttime&sortorder=ascending&max-results=10&futureevents=true&alt=json'

 $.get(url, function(data){
    console.log(data);
 });

这可以正确访问我的日历数据,但由于一些奇怪的原因,我不能让我访问我的事件的日期和时间,只是事件名称 .

任何人都可以对此有所了解吗?日历共享设置完全公开 .

1 回答

  • 2

    您需要调用不同的 endpoints . 我成功地拨打电话并获取列表(包括事件名称,日期和许多其他详细信息 .

    例如:

    {
    
       "kind": "calendar#event",
       "etag": "\"2814404343670000\"",
       "id": "bpgo6gtet1ao8j73kn770e6r20",
       "status": "confirmed",
       "htmlLink": "https://www.google.com/calendar/event?eid=YnBnbzZndGV0MWFvOGo3M2tuNzcwZTZyMjAgOXA3OXNsMmEzMXFncWZ2amtma3VwZGJmOG9AZw",
       "created": "2014-08-04T06:25:51.000Z",
       "updated": "2014-08-05T01:29:31.835Z",
       "summary": "Startup leadership women",
       "creator": {
        "email": "qceventscalendar@gmail.com",
        "displayName": "Sean Qian"
       },
       "organizer": {
        "email": "9p79sl2a31qgqfvjkfkupdbf8o@group.calendar.google.com",
        "displayName": "Queens Collective Events",
        "self": true
       },
       "start": {
        "dateTime": "2014-08-05T18:00:00+10:00"
       },
       "end": {
        "dateTime": "2014-08-05T21:00:00+10:00"
       },
       "iCalUID": "bpgo6gtet1ao8j73kn770e6r20@google.com",
       "sequence": 0,
       "reminders": {
        "useDefault": true
       }
      } ...
    

    要进行调用,请使用以下 endpoints :

    GET https://www.googleapis.com/calendar/v3/calendars/9p79sl2a31qgqfvjkfkupdbf8o%40group.calendar.google.com/events?key={YOUR_API_KEY}
    

    将GET url传递给您的AJAX调用(显然使用您的实际密钥切换API_KEY) .
    你可以从以下网址获取你的api密钥:https://console.developers.google.com

    如果您没有设置API帐户,我会创建一个,并使用Google Calendar API . 它会让你的生活更轻松 . 请注意,您可能需要将测试服务器(localhost?)添加到Google的API设置中,以便成功返回调用 .

    如果你需要帮助让我知道,我最近玩了很多Cal API ...

相关问题