Get group members with an admin account / deprecated GroupsManager class

我的梦境 提交于 2019-12-08 08:54:16

问题


The class GroupsManager will be turned off by November 20, 2014 https://developers.google.com/apps-script/reference/domain/groups-manager

I am using this class to manage some groups with my admin account as it's allowing access to group members WITHOUT BEING MEMBER OF.

Sample code here:

var group = GroupsManager.getGroup("some-group-name@mydomain.com");
var members = group.getAllMembers();

Using the Groups Service https://developers.google.com/apps-script/reference/groups/ is not an option, as stated in the documentation: "This service allows scripts to access Google Groups. It can be used to query information such as a group's email address, or the list of groups in WHICH THE USER IS MEMBER OF."

Using the AdminSDK as proposed in the GroupsManager "To manage your domain, use the Admin SDK Directory and Admin SDK Reports advanced services instead." is neither an option as there is no method to retrieve the members of a group...

So, anyone has a clue?

Thank you, Franck


回答1:


You can use the Admin SDK Directory service to do this. The method AdminDirectory.Members.list lists all the members of a group.




回答2:


Directory service = null;
        try
            {
                HttpTransport httpTransport = new NetHttpTransport();
                JacksonFactory jsonFactory = new JacksonFactory();
                GoogleCredential credential = new GoogleCredential.Builder()
                    .setTransport(httpTransport)
                    .setJsonFactory(jsonFactory)
                    .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
                    .setServiceAccountScopes(Arrays.asList(DirectoryScopes.ADMIN_DIRECTORY_USER))
                    .setServiceAccountUser(userEmail)
                    .setServiceAccountPrivateKeyFromP12File(
                        new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
                    .build();
                service = new Directory.Builder(httpTransport, jsonFactory, null)
                    .setHttpRequestInitializer(credential).setApplicationName("ShareFileUSer").build();
            }catch(Exception e)
            {
                System.out.println("Exception is : "+e);
            }



    Directory.Users.List userList = service.users().list().setCustomer("my_customer").setMaxResults(100);


来源:https://stackoverflow.com/questions/23883269/get-group-members-with-an-admin-account-deprecated-groupsmanager-class

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