【问题标题】:GroupsApp.getGroupbyEmail is returning no group foundGroupsApp.getGroupbyEmail 返回未找到组
【发布时间】:2020-01-23 07:23:56
【问题描述】:

我正在尝试使用 google 应用程序脚本通过其电子邮件地址获取组。这里只有一行代码很重要。

有问题的行是:

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。

【问题讨论】:

  • 考虑修剪你的代码。其中很大一部分与所提出的问题无关。请看sscce.org

标签: google-apps-script google-groups


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

    getGroupByEmail(电子邮件) 检索具有指定电子邮件的组 地址。如果组不存在或存在则抛出异常 无权查看。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-05
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 2018-12-16
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多