Reputation: 106
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?
Upvotes: 1
Views: 3261
Reputation: 3782
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 do EventDateTime().setDateTime()
if you want a timed event or if not, you can do something like:
new EventDateTime().setDate(new DateTime(true, new Date(), 0));
Upvotes: 10
Reputation: 4141
As documentation says, you need to pass timezone toDateTime
object if it is not set on EventDateTime
object(and in your case it is not set) using setTimeZone
method.
So either create new DateTime
object including timezone, or create new EventDateTime
object and set its timezone before sending request to server.
Upvotes: 0