【问题标题】:Calendar cannot be unsubscribed from. Try deleting instead无法取消订阅日历。尝试删除
【发布时间】:2015-06-09 12:52:18
【问题描述】:

试图了解我是否在这里做错了什么。

我正在尝试使用 Apps 脚本取消订阅日历,但它不允许我,我收到错误消息

日历 test.user@cadillacfairview.com 无法取消订阅。请尝试删除。

代码:

function anotherTest(){
  var cal = CalendarApp.getCalendarById('test.user@cadillacfairview.com');
  cal.unsubscribeFromCalendar(); 
}

我不拥有日历,但我确实拥有它的权利。 我尝试发出cal.deleteCalendar(),但它说“不允许采取行动”。

【问题讨论】:

    标签: google-apps-script google-calendar-api


    【解决方案1】:

    我遇到了完全相同的问题。 Google Apps 脚本日历服务似乎会产生这些错误,因为它试图删除实际日历,而不是仅仅取消订阅。

    我的工作解决方案涉及直接使用 Google Calendar API。

    具体方法是CalendarList: delete

    这会从 Google 日历侧边栏中的日历列表中删除一个条目,这与“取消订阅”相同。此外,它不会简单地将其从列表中“隐藏”,而是将其完全删除。

    var calendarList = CalendarApp.getAllCalendars();
    
    for (var i = 0; i < calendarList.length; i++) {
    
      var calendar = calendarList[i];
    
      // calendar.unsubscribeFromCalendar(); // results in "...cannot be unsubscribed from. Try deleting instead"
      // calendar.deleteCalendar(); // results in "...Action not allowed"
      // use the actual calendar API instead of Calendar service
    
      Logger.log('will remove calendar: ' + calendar.getName());
    
      var url = "https://www.googleapis.com/calendar/v3/users/me/calendarList/" + encodeURIComponent(calendar.getId());
    
      var requestBody                = {};
      requestBody.headers            = { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() };
      requestBody.method             = 'DELETE';
      requestBody.muteHttpExceptions = false;
    
      try {
    
        var response = UrlFetchApp.fetch(url, requestBody);
    
        Logger.log('response: ' + response); // if API call worked, response should be blank
    
        Logger.log('removed calendar: ' + calendar.getName());
    
      } catch(e) {
    
        Logger.log('failed to remove calendar: ' + e.message);
    
      }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 2021-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-21
      • 2016-07-12
      • 2013-02-21
      相关资源
      最近更新 更多