简体   繁体   English

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

[英]Google Calendar API return date, time and event name to Javascript

banging my head against the wall with Google's calendar API. 借助Google的日历API,我的头撞墙了。 My calendar is public, with the address of: 我的日历是公开的,地址为:

 9p79sl2a31qgqfvjkfkupdbf8o@group.calendar.google.com

I want to access the 10 closest events in the future, and put their date, time and event name onto my page. 我想将来访问最近的10个事件,并将它们的日期,时间和事件名称添加到我的页面上。 I'm trying to access this as follows: 我试图按如下方式访问它:

 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);
 });

This correctly accesses my calendar data, but for some bizarre reason doesn't let me access my events' date and times, just the event name. 这样可以正确访问我的日历数据,但是出于某种奇怪的原因,我无法访问事件的日期和时间,而只能访问事件名称。

Can anyone shed some light on this? 谁能对此有所启发? The calendar sharing settings are fully public. 日历共享设置是完全公开的。

You need to call a different endpoint. 您需要调用其他端点。 I was successfully able to make a call and get the list back (including event names, dates, and a lot of other details. 我成功拨打了电话,并拿回了清单(包括事件名称,日期和许多其他详细信息)。

For example: 例如:

{

   "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
   }
  } ...

In order to make the call, use the following endpoint: 为了进行呼叫,请使用以下端点:

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

Pass that GET url into your AJAX call (obviously switching API_KEY with your actual key). 将该GET URL传递到您的AJAX调用中(显然,用您的实际密钥切换API_KEY)。
You can get your api key from: https://console.developers.google.com 您可以从以下网址获取api密钥: https : //console.developers.google.com

If you don't have an API account set up, I would go and create one, and use the Google Calendar API. 如果您没有设置API帐户,我将创建一个帐户,然后使用Google Calendar API。 It will make your life much easier. 这将使您的生活更加轻松。 Keep in mind, you may have to add your testing server (localhost?) to Google's API settings in order for the call to return successfully. 请记住,您可能必须将测试服务器(localhost?)添加到Google的API设置中,才能使调用成功返回。

If you need help let me know, I've played around with the Cal API quite a bit lately... 如果您需要帮助,请告诉我,最近我已经使用Cal API了很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM