I'm using Java Google API client and I'm trying to create a Google Calendar Event.My authentication and calendar service initialization works (I'm able to log in and fetch my calendars events). The problem occurs when creating the event. Here is my code:
Event event = new Event();
event.setSummary( title );
event.setStart( new EventDateTime().setDate( new DateTime( new Date() ) ) );
event.setEnd( new EventDateTime().setDate( new DateTime( new Date() ) ) );
return _calendarService.events().insert( GOOGLE_CALENDAR_ID, event ).execute();
Here is the error I get:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request { "code" : 400, "errors" : [ { "domain" : "global", "message" : "Invalid value for: \"T\" found, can only parse bare date string: 2014-10-10T15:58:06.165+03:00", "reason" : "invalid" } ], "message" : "Invalid value for: \"T\" found, can only parse bare date string: 2014-10-10T15:58:06.165+03:00" }
Any ideas what I'm doing wrong here?
The problem is that you are doing
setDate()
and passing in a dateTime (which then results in the "T15:58:06.165" appended to your date). You can either doEventDateTime().setDateTime()
if you want a timed event or if not, you can do something like:new EventDateTime().setDate(new DateTime(true, new Date(), 0));
As documentation says, you need to pass timezone to
DateTime
object if it is not set onEventDateTime
object(and in your case it is not set) usingsetTimeZone
method.So either create new
DateTime
object including timezone, or create newEventDateTime
object and set its timezone before sending request to server.