Google Calendar API事件插入

时间:2012-10-20 03:30:45

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

我在尝试将事件插入日历时遇到问题。以下是我到目前为止的代码,取自Google API帮助:

Event event = new Event();
event.setSummary("Appointment");
event.setLocation("Somewhere");
ArrayList<EventAttendee> attendees = new ArrayList<EventAttendee>();
attendees.add(new EventAttendee().setEmail("attendeeEmail"));
event.setAttendees(attendees);
Date startDate = new Date();
Date endDate = new Date(startDate.getTime() + 3600000);
DateTime start = new DateTime(startDate, TimeZone.getTimeZone("UTC"));
event.setStart(new EventDateTime().setDateTime(start));
DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC"));
event.setEnd(new EventDateTime().setDateTime(end));
service.events().insert("primary", event).execute();

除了我不断获取

        Exception in thread "main"     

    com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request

"message" : "Invalid Value"

我做错了什么?

1 个答案:

答案 0 :(得分:1)

你试过这个吗?

attendees.add(new EventAttendee().setEmail("attendeeEmail@bla.com"));

我重现了这个错误:似乎google检查电子邮件是否有@符号。 添加@ bla.com解决了它。没有更多400错误请求