google-api - 在谷歌日历 API v3 中插入​​新的 calendarEntry 返回 404

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

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

我列出我的日历条目没有问题。但是插入新的 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"
 }
}

有任何想法吗?

最佳答案

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();
    }

关于google-api - 在谷歌日历 API v3 中插入​​新的 calendarEntry 返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11052792/

相关文章:

php - 如何使用 PHP 运行 Google Embed API 服务器端授权?

java - 异常 : 401 Unauthorized Error | com. google.api.client.auth.oauth2.TokenResponseException:401 未经授权

java - 使用 Google Drive Oauth 2.0 管理访问 token

java - 使用 API 和服务帐户创建的新日历不可见

java - 更新 Google 日历上的 Activity 会自动将 EventAtendee 设置为 self

java - 获取通过 OAuth2 验证的用户电子邮件地址

java - 使用 AccountManager 通过 Google API 进行身份验证

permissions - 启用谷歌电子表格API

python - Eclipse 无法识别 Google python-api-client 库

php - 谷歌日历预订系统