2017-09-26 28 views
0

尝试使用以下代码在Google Apps脚本界面(script.google.com)中列出并更新Google日历ACL )。我已经在GSuite帐户上启用了日历API,并且可以在开发人员控制台中看到正在命中的API(使用404和403)。在Apps脚本中使用Calendar.Acl.list列出Google日历ACL导致错误“执行失败:未找到”

下面的代码中列出的calendarId是假的,但是,我正在使用的那个确实存在,并且在开发人员门户使用尝试此API窗体工作正常。

https://developers.google.com/google-apps/calendar/v3/reference/acl/list

我想我有足够的授权,因为我使用的开发人员门户和应用程序脚本界面上的相同GSuite帐户登录。

对Google Apps脚本环境或OAuth授权有任何限制,禁止此代码仅在Apps脚本中运行?

function test() 
{ 
    var calendar_acl_list; 
    calendar_acl_list = Calendar.Acl.list({calendarId: '[email protected]'}); 
Logger.log('%s', calendars_acl_list); 


} 

可能是因为我的简单代码不正确,但是错误没有提供足够的信息来排除故障。这是在Apps Script界面​​中的视图>执行脚本菜单中显示的错误。

[17-09-26 14:13:31:492 PDT] Execution failed: Not Found (line 32, file "Code") [0.066 seconds total runtime] 

即使上述代码不起作用。下面的代码是:

function test2() 
{ 
var calendars; 
calendars = Calendar.CalendarList.list({maxResults: 100}); 
Logger.log('%s', calendars); 
} 
+0

你使用任何类型的OAuth库这个的?我不认为它完全自动地为你处理这个问题。您仍然可能必须授予您的脚本范围。请参阅“使用OAuth向服务提出请求”:https://developers.google.com/apps-script/guides/services/external – John

+0

我正在https://script.google.com/上撰写应用程序脚本。它会在执行AFAIK之前提示进行OAuth访问批准。 – Farhannibal

+0

这是分配给相关的谷歌电子表格的范围: 谷歌日历 你的域管理你的日历 谷歌服务 查看用户 – Farhannibal

回答

0

Calendar.Acl.list方法的正确用法是:

calendarId = '[email protected]'  
calendars_acl_list = Calendar.Acl.list(calendarId); 
Logger.log('%s', calendars_acl_list);