为什么我得到"无效的JSON字符串"从高级日历服务?

时间:2014-07-28 16:44:04

标签: google-apps-script

我尝试按照文档here从Google Apps脚本调用高级日历服务。我已经设置了我认为非常简单的电话:

  // Retrieve busy info from Calendar API
  var events = Calendar.Freebusy.query({
    timeMin: startDateTime.toISOString(),
    timeMax: endDateTime.toISOString(),
    items: [
      {id: "<Calendar Id>"},
      {id: "<Another Calendar Id>"}
    ]
  });
  var len = events.length;
  Logger.log(len);
  for(var i = 0; i < len; i++) {
    Logger.log(events[i].getTitle());
  }

(显然,我的代码版本中有真实的日历ID。)

但是,当我运行上面的代码时,我在第一行遇到错误。执行记录显示以下错误消息:

[14-07-28 12:41:05:640 EDT] Execution failed: Invalid JSON string: {
 "kind": "calendar#freeBusy",
 "timeMin": "2014-07-28T14:30:00.000Z",
 "timeMax": "2014-08-01T20:00:00.000Z",
 "calendars": {
  "<Calendar Id>": {
   "busy": [
    {
     "start": "2014-07-28T20:00:00Z",
     "end": "2014-07-28T21:00:00Z"
    }
   ]
  },
  "<Another Calendar Id>": {
   "busy": [
    {
     "start": "2014-07-28T17:00:00Z",
     "end": "2014-07-28T17:30:00Z"
    },
    {
     "start": "2014-07-28T18:00:00Z",
     "end": "2014-07-28T20:00:00Z"
    },
    {
     "start": "2014-07-29T12:30:00Z",
     "end": "2014-07-29T14:00:00Z"
    },
    {
     "start": "2014-07-29T15:30:00Z",
     "end": "2014-07-29T17:00:00Z"
    },
    {
     "start": "2014-07-29T23:50:00Z",
     "end": "2014-07-31T01:07:00Z"
    },
    {
     "sta... (line 33, file "Code") [0.837 seconds total runtime]

我知道为什么我会收到一个&#34;无效的JSON字符串&#34;错误?

1 个答案:

答案 0 :(得分:0)

我想问题出在这个关键要素上:"<Calendar Id>""<Another Calendar Id>"。尝试使用序列字符串以及通常具有特殊含义的withoud <>字符。

相关问题