400 错误请求 在 Google 日历中插入活动

问题描述 投票:0回答:3

我正在使用 Google Calendar API,并且尝试向 API 发送插入事件的请求,但收到错误。

这是我发送的请求:

POST https://www.googleapis.com/calendar/v3/calendars/riteshmehandiratta%40gmail.com/events?key={YOUR_API_KEY}

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

{

 "end": {
  "date": "2/14/2007"
 },
 "start": {
  "date": "2/14/2007"
 },
 "kind": "calendar#event",
 "summary": "Hello World"
}

我得到的回应是:

400 Bad Request

- Hide headers -

cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  122
content-type:  application/json; charset=UTF-8
date:  Sat, 23 Mar 2013 17:36:22 GMT
expires:  Sat, 23 Mar 2013 17:36:22 GMT
server:  GSE

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

我无法弄清楚为什么会收到错误的请求错误。

google-app-engine google-calendar-api
3个回答
3
投票

据我所知,您的日期格式是错误的,API 文档表明:

 The date, in the format "yyyy-mm-dd", if this is an all-day event. 

您可能需要使用本页底部的“尝试”表单来首先确保您的请求有效:

https://developers.google.com/google-apps/calendar/v3/reference/events/insert#try-it

祝你好运!


0
投票

这就是我所做的(PHP):

//Passed in a GET variable name of 'date'
//Tells parser the current format
$dt = DateTime::createFromFormat("d/m/Y", $_GET['date']);

//Adding the event start date, modifying the format to suit googles encoding
$start->setDate($df->format("Y-m-d"));

上面的脚本片段对我有用。

Rohan 关于其格式化条件的说法是正确的。


0
投票

记住你必须有结束时间

© www.soinside.com 2019 - 2024. All rights reserved.