How to update Google Group Settings with Google Apps Script

人走茶凉 提交于 2019-12-12 19:21:00

问题


I have a Google Apps Script which has all the permissions it needs, with the Group Settings API on and working, but does not change certain things. There are no errors given, but the only thing that changes is the name, and the rest does nothing. This is the script:

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:


Ok, after a bit of investigation and experimentation, I found that there was another API and another format that had to be used so that it will work. You need to activate the Groups Settings API (not the Admin Directory API) and you can see the documentation here.

The format is the following:

 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);
 }


来源:https://stackoverflow.com/questions/51461276/how-to-update-google-group-settings-with-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!