How to get all users in one organization unit using Google Directory API

℡╲_俬逩灬. 提交于 2019-12-08 03:11:47

问题


In the new released Google Directory API, I cannot find a method to get all users in a specific organization unit of Google Apps. Is it possible? And how? Based on the Google Directory API document, programmers can get all the organization units, or all the users for the whole domain, but there is no description on how to get users of one organization unit. This feature is crucial important to construct the organizations/users hierarchical tree. Please help, thanks.


回答1:


There is no way to get the list of users under a single OU (and only those users). However, you can just grab the full list of users in the Google Apps instance along with their OU using a call to:

https://www.googleapis.com/admin/directory/v1/users?customer=my_customer&fields=nextPageToken%2Cusers(orgUnitPath%2CprimaryEmail)

based on Vic Fryzel's presentation at I/O, I believe Google plans to continue to improve the capabilities of the query parameter, eventually allowing a query based on OU (as well as other query parameters).




回答2:


After some back and forth with the google dev relations team I was able to get it to work bay adding a query parameter orgUnitPath=/SOMEPATH to the list users call. Here is an example using the google api php client that's using the directory API: $users = $directory->users->listUsers(array("domain"=>"example.com","query"=>"orgUnitPath=/SOMEPATH"));

Hope this helps!




回答3:


UsersResource.ListRequest request = service.Users.List(); 
request.Customer = "my_customer";
request.Query = "orgUnitPath=" + "'" + "/testOu/under testOu/testOu1" + "'"; 


来源:https://stackoverflow.com/questions/16975052/how-to-get-all-users-in-one-organization-unit-using-google-directory-api

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