Google脚本Google日历TypeError:无法调用方法"createEvent"的null [英] Google script google calendar TypeError: Cannot call method "createEvent" of null

查看:73
本文介绍了Google脚本Google日历TypeError:无法调用方法"createEvent"的null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循Google脚本日历中的示例.除了calendarID之外,我没有更改任何代码.代码与示例所示完全相同:

I am trying to follow the examples here in google script calendar. I didn't change the code except for the calendarID thing. The code is exactly the same as the example shows:

function createEvent(calendarId) {
      var cal = CalendarApp.getCalendarById(calendarId);
      var title = 'Script Demo Event';
      var start = new Date("April 1, 2012 08:00:00 PDT");
      var end = new Date("April 1, 2012 10:00:00 PDT");
      var desc = 'Created using Google Apps Script';
      var loc = 'Script Center';

      var event = cal.createEvent(title, start, end, {
          description : desc,
          location : loc
      });
    };

我不确定是否需要将calendarId更改为我的'xxxxx@gmail.com'.但是当我运行这些代码时,错误是TypeError: Cannot call method "createEvent" of null. (line 15, file "Code")

I am not sure if I need to change calendarId to my 'xxxxx@gmail.com'. But when i run these code,the error is TypeError: Cannot call method "createEvent" of null. (line 15, file "Code")

出什么问题了?

推荐答案

错误消息告诉您,没有具有此ID的日历,非域用户的日历ID的通常形式类似于 h22xxxxxxxjb6ul4hu7ft8@group.calendar.google.com ,对于域: domain.xxx_se8nmkl1qsqxxxxxxxxx28ufs@group.calendar.google.com .

The error message is telling you that there is no Calendar with this ID, the usual form of a calendar ID for a non domain user is something like h22xxxxxxxjb6ul4hu7ft8@group.calendar.google.com, and for a domain : domain.xxx_se8nmkl1qsqxxxxxxxxx28ufs@group.calendar.google.com.

您检查输入的ID是否有效吗?

Have you checked that the ID you entered is valid ?

您还可以使用getCalendarsByName('calendarName')测试相同的脚本,该脚本将返回日历中具有该名称的所有日历的数组,在这种情况下,您通常必须使用getCalendarsByName('calendarName')[0]选择第一个.

You can also test the same script using getCalendarsByName('calendarName') which will return an array of all the calendars having this name in your calendars, in this case you'll have to generally pick the first one using getCalendarsByName('calendarName')[0].

您还可以通过getDefaultCalendar()使用默认日历,这是您的Gmail地址附带的日历. 文档.

You can also use your default calendar using getDefaultCalendar(), this is the one attached to your gmail address. All this is pretty well illustrated in the documentation.

此小代码可让您检查您拥有或订阅的所有日历的ID.

This small code will allow you to check the IDs of all the calendars you own or subscribed to.

function testCals(){
  var cals = CalendarApp.getAllCalendars();
  for(var n in cals){
    Logger.log(' calendar ID = '+cals[n].getId()+'\nName = '+cals[n].getName()+'\n')
  }
}

这篇关于Google脚本Google日历TypeError:无法调用方法"createEvent"的null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆