如何使用Google Apps脚本更新Google网上论坛设置

时间:2018-07-22 01:15:31

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

我拥有一个Google Apps脚本,该脚本具有所需的所有权限,并且启用了“组设置” API,但没有更改某些内容。没有给出任何错误,但是唯一改变的是名称,其余的什么都不做。这是脚本:

function modgroup() {
  var groupKey = 'finaltest@school.edu.mx';

  var resource = {
   name: "finalfour", 
   whoCanContactOwner: "ALL_MEMBERS_CAN_CONTACT",
   whoCanJoin: "INVITED_CAN_JOIN", 
   whoCanViewMembership: "ALL_MEMBERS_CAN_VIEW", 
   whoCanViewGroup: "ALL_MEMBERS_CAN_VIEW",
   whoCanInvite: "ALL_MANAGERS_CAN_INVITE", 
   whoCanAdd: "ALL_MANAGERS_CAN_ADD", 
   allowExternalMembers: false,
   whoCanPostMessage: "ALL_MEMBERS_CAN_POST", 
   allowWebPosting: false 
  }

  AdminDirectory.Groups.update(resource, groupKey);

}

1 个答案:

答案 0 :(得分:2)

好吧,经过一番调查和实验,我发现必须使用另一种API和另一种格式才能使其正常工作。您需要激活网上论坛设置API(而不是Admin Directory API),并且可以查看文档here

格式如下:

 function editGroup(){
    var groupId = 'finaltest@school.edu.mx';
    var group = AdminGroupsSettings.newGroups();
     group.name = 'NAME';
     group.description = 'DESCRIPTION';
     group.whoCanAdd = 'NONE_CAN_ADD';
     group.whoCanJoin = 'INVITED_CAN_JOIN';
     group.whoCanViewMembership = 'ALL_MEMBERS_CAN_VIEW';
     group.whoCanViewGroup = 'ALL_MEMBERS_CAN_VIEW';
     group.whoCanInvite = 'ALL_MANAGERS_CAN_INVITE';
     group.allowExternalMembers = false;
     group.whoCanPostMessage = 'ALL_MEMBERS_CAN_POST';
     group.allowWebPosting = true;
     group.showInGroupDirectory = false;
     group.allowGoogleCommunication = false;
     group.membersCanPostAsTheGroup = false;
     group.includeInGlobalAddressList = false;
     group.whoCanLeaveGroup = 'NONE_CAN_LEAVE';

   AdminGroupsSettings.Groups.patch(group, groupId);
 }