Google Calendar API事件插入始终返回404"未找到"错误

Jia*_*ang 18 google-calendar-api

我从这里尝试了日历插入示例:https://developers.google.com/google-apps/calendar/v3/reference/events/insert#examples 无论我使用哪个属性,我总是得到404"未找到"错误.任何人都可以对此有所了解吗?非常感谢!!!

POST https://www.googleapis.com/calendar/v3/calendars/test/events?sendNotifications=false&fields=start&key={YOUR_API_KEY}

Content-Type:  application/json
Authorization:  Bearer ya29.AHES6ZQaT3-Tj_bviwaY9Xi3gDspuBbCtEKtidnZkTXuWpI
X-JavaScript-User-Agent:  Google APIs Explorer

{
 "end": {
  "date": "2012-07-11"
 },
 "start": {
  "date": "2012-07-09"
 }
}
Run Code Online (Sandbox Code Playgroud)

回复:404未找到

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*aly 13

我相信它告诉你无法找到日历"测试"资源.你创建了一个名为"test"的日历吗?如果将"test"替换为"primary"(主日历),则Explorer应该可以正常工作.

  • 我有同样的问题,我不能使用主日历,我需要连接到其他日历. (2认同)

Car*_*ori 10

今天我在非主日历上遇到了同样的问题。现在已经解决了,请按以下步骤操作:

  1. 进入Service Accounts,进入你的项目,创建一个 Service account,然后进入 Key Tabs 并创建一个 Key,现在就保存了一个 Json 文件。

在此输入图像描述

在此输入图像描述

  1. 打开 Json 并查看“client_email”属性。

在此输入图像描述

  1. 现在转到您的非主日历,然后转到“设置和共享”部分。

在此输入图像描述

  1. 现在,添加在“与特定人员共享”部分中的“client_email” json 属性上设置的电子邮件。

在此输入图像描述

  1. 再次测试,现在可以了!

注意:此解决方案为我提供带有服务帐户身份验证方法的 PHP Web 应用程序。您也必须使用服务帐户方法而不是OAuth 2.0


小智 6

致 JuanPablo,关于非主要日历:

如果是非主日历,您必须使用id(以电子邮件地址的形式)作为calendarId

示例:假设您有一个名为“test”的日历。你可以这样得到它的id

GET https://www.googleapis.com/calendar/v3/users/me/calendarList?key={YOUR_API_KEY}
->
{
 "kind": "calendar#calendarList",
...
 "items": [
  {

   "kind": "calendar#calendarListEntry",
   "etag": ...,
   "id": "123example123example123xxx@group.calendar.google.com",
   "summary": "test",
   "description": "Testing calendar for development of Calendar related applications",
...
   }
  }
 ]
}
Run Code Online (Sandbox Code Playgroud)

您的帖子将如下所示

POST https://www.googleapis.com/calendar/v3/calendars/123example123example123xxx@group.calendar.google.com/events?sendNotifications=false&fields=start&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)