Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar V3 API Issues?

For some reason i am getting events back from 2010 that are returning in this API call:

https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?maxResults=15&key={KEY HERE}

Here is some of the JSON from the response (Inside the Items Array):

  {
     "kind":"calendar#event",
     "etag":"\"SaH0JPgxpZtQtKmztOIhZtDaAls/MA\"",
     "id":"_64oj8e9m8d1kab9p8cs48b9k68sj8ba284q48b9k64o4cd1p6crj6cq370",
     "status":"confirmed",
     "htmlLink":"LINK HERE",
     "created":"2010-07-29T15:10:49.000Z",
     "updated":"1970-01-01T00:00:00.000Z",
     "summary":"Blood Drive",
     "creator":{
        "email":"[email protected]",
        "displayName":"Elite Gamer",
        "self":true
     },
     "organizer":{
        "email":"[email protected]",
        "displayName":"Elite Gamer",
        "self":true
     },
     "start":{
        "dateTime":"2010-08-23T14:00:00-05:00"
     },
     "end":{
        "dateTime":"2010-08-23T19:00:00-05:00"
     },
     "iCalUID":"11496CCE-9C8D-4294-BA4D-410F493733C8",
     "sequence":4
  }

I have had evens all the way up till now (2014). The API is also showing that it was update in the 1900s???.

Did i mess up something? Is there a parameter i missed? I expect more out of google than this.

Also, another thing i thought was weird. Google Calendar also returns two different dates?! a dateTime and a date. (Dependent on a All Day Event). Is this supposed to happen? It makes developers have to check which one was sent in the response and then parse the date dependent upon that. Either that, or i am missing a parameter in my request.

UPDATE

After looking around, i found this:

http://www.google.com/calendar/feeds/[email protected]/public/full?alt=json&max-results=15

This get the exact information, but in a different format. However, this does return the correct date; but the dates are still formatted differently for some reason. Why is this? And which one should i use?

like image 816
Hunter Mitchell Avatar asked Mar 23 '26 05:03

Hunter Mitchell


1 Answers

For some reason i am getting events back from 2010 that are returning in this API call:

https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?>maxResults=15&key={KEY HERE}

Use the timeMin parameter query in your URL. By default you don't filter by date, so you just get all results. Filtering maxResults just limits the amount of events returned.

https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?maxResults=15&timeMin=2014-01-01T01:01:01.000Z&key={KEY HERE}

I have had evens all the way up till now (2014). The API is also showing that it was >update in the 1900s???.

Problably because the event has never been updated. It isn't documented in the API: https://developers.google.com/google-apps/calendar/v3/reference/events/list

Also, another thing i thought was weird. Google Calendar also returns two different >dates?! a dateTime and a date. (Dependent on a All Day Event). Is this supposed to happen? >It makes developers have to check which one was sent in the response and then parse the >date dependent upon that. Either that, or i am missing a parameter in my request.

Yes, this is supposed to happen according to the documentation. https://developers.google.com/google-apps/calendar/v3/reference/events#resource

The date, in the format "yyyy-mm-dd", if this is an all-day event.

The time, as a combined date-time value (formatted according to RFC 3339). A time zone >offset is required unless a time zone is explicitly specified in timeZone.

For myself, I have been strugling with getting everything to work as well, so I hope this helped you out.

As for deserializing. I used Newtonsoft.JSON to deserialize the appointment in .NET. First make a root object, because you are serializing a list of events.

public class RootObject
{
    public RootObject() {}
    //parameters you want to retrieve from the Calendar.
    public List<GoogleEvent> events {get;set;}
}

public class GoogleEvent
{
    public GoogleEvent(){}

    [JsonProperty("calendarId")] //specify which JSON parameter needs to be mapped
    public string Id {get;set;}
    //all parameters you need
}

then use the NewtonSoft deserializer to get the RootObject which containt all events from the Json you retrieved.

NewtonSoft.Json.JsonConvert.DeserializeObject<RootObject>(JSONSTRING);
like image 105
Edwin van Vliet Avatar answered Mar 24 '26 19:03

Edwin van Vliet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!