Listing users using Google Admin SDK in Java

邮差的信 提交于 2019-12-23 04:43:57

问题


I want to list users in a domain as defined in google. I saw that it's available through the Google Admin Directory SDK. Although, I couldn't find any examples or documentation how can I use it in Java. I already have got the authorization part. I'm just not sure which objects should I use from the API and how.

Thanks!


回答1:


Here is an example with the relevant imports

From the docs (https://developers.google.com/admin-sdk/directory/v1/reference/users/list)

As an account administrator, you can also use the my_customer alias to represent your account's customerId

import java.io.IOException;
import java.util.List;

import com.google.api.services.admin.directory.Directory;
import com.google.api.services.admin.directory.model.User;
import com.google.api.services.admin.directory.model.Users;

    public static List<User> listUser(Directory directory) throws IOException {
        Users users = directory.users().list().setCustomer("my_customer").execute();
        return users.getUsers();
    }



回答2:


I have answered a similar question at GoogleApps Directory APIs To Manage Users

You should try out the java client library.

https://developers.google.com/admin-sdk/directory/v1/api-lib/java

It has a quickstart for directory API in Java, which should help you set up and get started.

Additionally, here is the javadoc reference for this specific API

https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/java/latest/



来源:https://stackoverflow.com/questions/21671781/listing-users-using-google-admin-sdk-in-java

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