在Google日历API v3中插入新的calendarEntry会返回404

时间:2012-06-15 14:36:05

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

我使用google-api-services-calendar v3 for java。

我列出没有问题我的calendarEntries。但是插入新的calendarEntry失败了。

我使用与样本相同的代码:

CalendarListEntry newCal = new CalendarListEntry();
newCal.setId(calTitle);
newCal.setSummary(calTitle);
newCal.setTimeZone("Europe/Paris");
CalendarListEntry execute = null;
try {
    execute = service.calendarList().insert(newCal).execute();
} catch (IOException e) {
    e.printStackTrace();
}

未创建日历。在我的日志中:

CONFIG: {"id":"A_TEST","summary":"A_TEST","timeZone":"Europe/Paris"}
15 juin 2012 16:20:45 com.google.api.client.http.HttpRequest execute
CONFIG: -------------- REQUEST  --------------
POST https://www.googleapis.com/calendar/v3/users/me/calendarList
Accept-Encoding: gzip
Authorization: <Not Logged>
User-Agent: Google-HTTP-Java-Client/1.10.2-beta (gzip)
Content-Type: application/json; charset=UTF-8
Content-Encoding: gzip
Content-Length: 69

CONFIG: Total: 60 bytes
CONFIG: {"id":"A_TEST","summary":"A_TEST","timeZone":"Europe/Paris"}
15 juin 2012 16:20:46 com.google.api.client.http.HttpResponse <init>
CONFIG: -------------- RESPONSE --------------
HTTP/1.1 404 Not Found
X-Frame-Options: SAMEORIGIN
Date: Fri, 15 Jun 2012 14:07:52 GMT
Content-Length: 120
Expires: Fri, 15 Jun 2012 14:07:52 GMT
X-XSS-Protection: 1; mode=block
Content-Encoding: gzip
Content-Type: application/json; charset=UTF-8
Server: GSE
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff

CONFIG: Total: 165 bytes
CONFIG: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

RTFM!

我不是很好的uri。正确的插入必须在https://www.googleapis.com/calendar/v3/calendars

而不是https://www.googleapis.com/calendar/v3/users/me/calendarList

代码是:

    Calendar newCal = new Calendar();
    newCal.setSummary(calTitle);
    newCal.setTimeZone("Europe/Paris");

    Calendar createdCalendar = null;
    try {
        createdCalendar = service.calendars().insert(newCal).execute();
    } catch (Exception e){
        e.printStackTrace();
    }