我正在使用 Java Google API 客户端,并且正在尝试创建 Google 日历 Activity 。 我可以登录并获取我已经创建的事件。
我一直在关注 API 示例,但收到以下错误,并查看了其他类似的问题,但仍然无法使其正常工作:
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?"
}
这是我的代码,我将字符串传递到我的日期时间中:
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())
知道出了什么问题吗?
最佳答案
可能重复。
但是,很快 - 是的,您正在尝试使用需要 DateTime 格式的函数,但您将不同的日期对象作为参数提供。
“新的日期时间(开始数据);” startData 不是 DateTime,而是日期。
请查看此帖子:Google Calendar API (Java) - Invalid time format when creating Google Calendar Event
它有您的问题和两个解决方案。
关于java - (Java) 插入事件时 Google 日历格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45990405/