Melrache
Melrache

Reputation: 13

(Java) Google Calendar format error when inserting Event

I'm using Java Google API client and I'm trying to create a Google Calendar Event. I'm able to login and fetch events I already have created.

I've been following the API examples and I'm getting the following error and looked at the other similar questions and still can't get it working:

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: 2017-08-31T12:00:00.000-01:00 Have you accidentally used DateTime instead of a Date?",
"reason" : "invalid"
  } ],
  "message" : "Invalid value for: \"T\" found, can only parse bare date string: 2017-08-31T12:00:00.000-01:00 Have you accidentally used DateTime instead of a Date?"
} 

This is my code, I'm passing Strings into my DateTimes:

DateTime startDate = new DateTime(startData);
    EventDateTime start = new EventDateTime();
    start.setDate(startDate);
    start.setTimeZone("Europe/Stockholm");
    DateTime endDate = new DateTime(endData);
    EventDateTime end = new EventDateTime();
    end.setDate(endDate);
    end.setTimeZone("Europe/Stockholm");
    Event event = new Event();
    event.setDescription(lessons.get(i).getDescription());
    event.setStart(start);
    event.setEnd(end);
    event.setLocation(lessons.get(i).getLocation());
    event.setSummary(lessons.get(i).getName())

Any idea what's going wrong?

Upvotes: 0

Views: 682

Answers (1)

1istbesser
1istbesser

Reputation: 127

Possible duplicate.

However, shortly - Yes, you are trying to use a function which require a DateTime format, but you feed as a parameter a date object which is different.

"new DateTime(startData);" startData isn't DateTime, but date.

Please checkout this post: Google Calendar API (Java) - Invalid time format when creating Google Calendar Event

it has your problem and two solutions for it.

Upvotes: 1

Related Questions