【问题标题】:Catching error with Usermanager.getUser() in Google Apps Script在 Google Apps 脚本中使用 Usermanager.getUser() 捕获错误
【发布时间】:2012-06-08 16:47:07
【问题描述】:

我正在使用 Google 电子表格创建一个脚本文件,该文件必须处理获取我的 Google Apps 域上的用户信息。我拥有管理员权限并且启用了 Provisioning API。在我的代码中,我试图在 Google Apps 域(未找到用户)上查找特定用户时捕获错误,而是显示一条消息并继续执行程序的其余部分。当用户没有错误时,我在这里使用的 try-catch 语句有效。但是,当检索用户时出现错误时,我收到错误:“序列化继续时出现意外异常”。这是我的代码:

function testOfDomainAccess() {

var i=0;
var anArray= ["johhn.smith", "susan.que]; //john smith misspelled
var user;

for (i=0; i < anArray.length; ++i)
{ 
Logger.log("\nThe current user being processed is " + anArray[i]);

try 
{
user = UserManager.getUser (anArray [i]);
}
catch (error)
{
  Browser.msgBox("Error: " + error.name + "\n Check your spreadsheet for misspellings of " + anArray[i] + " and We will continue to the next user.");
  user = null;
}

if (user != null) {
//Perform tasks 
}

else
  Logger.log("User not found in domain. Moving on the next item in the array.");
}

如果有人能帮助解决这个问题,我将不胜感激。我是 Google Apps 脚本和配置 API 的新手。谢谢!

【问题讨论】:

    标签: google-api google-apps-script


    【解决方案1】:

    看起来与http://code.google.com/p/google-apps-script-issues/issues/detail?id=980 报告的错误相同。

    解决方法是用 Logger.log() 替换 Browser.msgBox() 调用,您的脚本应该按预期运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-10
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      相关资源
      最近更新 更多