最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Calendar.Insert API returning 400 'required' - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a calendar via the Google javascript API. OAuth authentication is working fine : I'm able to get a list of calendars using:

gapi.client.calendar.calendarList.list();

However, when I try to create a calendar with:

gapi.client.calendar.calendars.insert(
{
    "summary": "A New Calendar",
    "description": "Generated by Ben",
    "timezone" : "Australia/Sydney"
});

I get:

{
  "error": {
  "code": 400,
  "message": "Required",
  "data": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required"
   }
  ]
 },
 "id": "gapiRpc"
}

In doco for other APIs it shows this response, but with a list of the required arguments that are missing.

Is there any way to determine what 'required' parameter I'm missing? I've tested it with the API Explorer and my parameters appear to work fine.

I'm trying to create a calendar via the Google javascript API. OAuth authentication is working fine : I'm able to get a list of calendars using:

gapi.client.calendar.calendarList.list();

However, when I try to create a calendar with:

gapi.client.calendar.calendars.insert(
{
    "summary": "A New Calendar",
    "description": "Generated by Ben",
    "timezone" : "Australia/Sydney"
});

I get:

{
  "error": {
  "code": 400,
  "message": "Required",
  "data": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required"
   }
  ]
 },
 "id": "gapiRpc"
}

In doco for other APIs it shows this response, but with a list of the required arguments that are missing.

Is there any way to determine what 'required' parameter I'm missing? I've tested it with the API Explorer and my parameters appear to work fine.

Share Improve this question edited Feb 23, 2023 at 13:08 Benyamin Jafari 34k35 gold badges160 silver badges177 bronze badges asked Feb 26, 2012 at 14:17 Ben HughesBen Hughes 1,53914 silver badges20 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 22

Finally figured this out. The properties need to be in a 'resource' object:

gapi.client.calendar.calendars.insert(
{
    "resource" :
    {"summary": "A New Calendar",
    "description": "Generated by Ben",
    "timezone" : "Australia/Sydney"}
});

The doco doesn't mention this, but if you look at the response to the initial call to gapi.auth.authorize you'll find JSON describing the entire API for the scope you've specified.

But I could normally create a new calendar using POST https://www.googleapis.com/calendar/v3/calendars API according to the documentation:

body = {
    'summary': 'calendarSummary',
    'timeZone': 'America/Los_Angeles'
}
发布评论

评论列表(0)

  1. 暂无评论