Pergunta

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

https://www.googleapis.com/calendar/v3/calendars/myEmailHere@gmail.com/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":"myEmailHere@gmail.com",
        "displayName":"Elite Gamer",
        "self":true
     },
     "organizer":{
        "email":"myEmailHere@gmail.com",
        "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/myEmail@gmail.com/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?

Foi útil?

Solução

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

https://www.googleapis.com/calendar/v3/calendars/myEmailHere@gmail.com/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/myEmailHere@gmail.com/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);

Outras dicas

updated is before created, that is weird. I haven't notice that before. It should at least as the same as created, but it's showing 1970-01-01T00:00:00.000Z. This must be a unix time which is 0. Google did something wrong. But your calendar event is created at 2010. You can just add new event to see if it goes right.

And all dates are formatting according to RFC 3339. You can use library to parse them.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top