GroupsApp.getGroupbyEmail返回未找到组

时间:2019-05-09 20:24:59

标签: google-apps-script google-groups

我正在尝试使用Google Apps脚本通过其电子邮件地址获取论坛。这里只有一行真正重要的代码。

有问题的行是:

var WSGroup = GroupsApp.getGroupByEmail("Group_Email_Address@domain.com");

我知道电子邮件地址正确。我知道拼写正确。我在管理控制台中与出色的Google服务台人员一起打开了一个票证,并确认所讨论的小组与我所知道的另一个小组具有相同的设置。我的问题是这个。当相同的代码将找到具有相同权限设置的任何其他组时,为什么代码无法找到该组。在我的头撞到墙上反复造成永久性损坏之前,我们将不胜感激。

function getGroups(){
  //gets the current users email address then checks it against all the groups listed below. 
  //When the user is found in that group the proper excel sheet gets their time stamp and their doc is moved to the right folder.
  var check = checkTimes();
  //if(check == 1) {
  //  return 0;
  //}
  //else {
    var user = Session.getActiveUser().getEmail();
    try {
      //the groups
      var CACGroup = GroupsApp.getGroupByEmail("group1@domain.com");
      var HSGroup = GroupsApp.getGroupByEmail("group2@domain.com");
      var JHGroup = GroupsApp.getGroupByEmail("group3@domain.com");
      var JSGroup = GroupsApp.getGroupByEmail("group4@domain.com");
      var CSGroup = GroupsApp.getGroupByEmail("group5@domain.com");
      var WSGroup = GroupsApp.getGroupByEmail("group6@domain.com"); \\var WSGroup using group6@domain is the line in question.
    }
    catch(e){
      DocumentApp.getUi().prompt("There was an error with your group memberships! Report this to tech! Error: " + e);
    }

    var doc = DocumentApp.getActiveDocument();
    var docID = doc.getId();
    //If user is in CAC group timestamp the CAC excel sheet then move the document to the CAC signed docs folder.
    try{
      if(CACGroup.hasUser(user)){
        var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 1');
        setStatus(user, googleSheet, doc);
      }
      if(HSGroup.hasUser(user)){
        var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 2');
        setStatus(user, googleSheet, doc);
      }
      if(JHGroup.hasUser(user)){
        var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 3');
        setStatus(user, googleSheet, doc);
      }
      if(JSGroup.hasUser(user)){
        var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 4');
        setStatus(user, googleSheet, doc);
      }
      if(CSGroup.hasUser(user)){
        var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 5');
        setStatus(user, googleSheet, doc);
      }
      if(WSGroup.hasUser(user)){
        var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 6');
        setStatus(user, googleSheet, doc);
      }
    }
    catch(e){
      var prompt = 'There was an issue accessing the excel sheet for your building!' ;
      DocumentApp.getUi().alert(prompt);
    }
    var prompt = 'Document sent to your main office!';
    DocumentApp.getUi().alert(prompt);
  //}
}

域中的任何用户都应该能够找到该网上论坛并查看其成员。我已经在admin.google.com和groups.google.com中确认了这些设置。相同的代码可以找到其他组,因此已经允许并打开了必要的API。

2 个答案:

答案 0 :(得分:1)

要跟进Calre D.的回应,Google Apps脚本文档说:

getGroupByEmail(电子邮件) 检索具有指定电子邮件的组 地址。如果该组不存在或您存在,则引发异常 没有查看权限。

https://developers.google.com/apps-script/reference/groups/groups-app#detailed-documentation

答案 1 :(得分:0)

我最近遇到了这个问题,这是我们所做的:

运行脚本的帐户必须是您正在检查的组的成员/经理/所有者。在您的情况下,“ group1@domain.com”,“ group2@domain.com”等...

我不确定Google是否更新了权限,但这通过创建用于处理脚本的通用帐户,将其添加到组中并使用该帐户来运行脚本为我们解决了问题。