java - (Java) 插入事件时 Google 日历格式错误

标签 java google-api google-calendar-api google-api-java-client

我正在使用 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/

相关文章:

c# - 如何在私有(private)浏览器 session 中询问用户许可?

java - 谁能告诉我为什么在使用 SSL 时在 Java 中出现错误?

api - 通过 API 访问 “Anyone with the link” Google 电子表格

ios - 使用 GTMOAuth2ViewControllerTouch 进​​行身份验证时执行 moments.insert

Python Mocking - 如何模拟 Google 的 storage.client?

java - 建立预约网站的最简单方法是什么?

android - 在不询问用户的情况下自动在 Android 日历上创建事件?

java - Path2D 绘制错误?

java - 使用多线程读取HDFS

java - 为什么解析的 Double 行为不正确?