问题
I borrowed code from here to download directory data from my Google domain into a spreadsheet. All I changed in the code was to replace OpenByURL with OpenByID because of an invalid argument error. Now it works, except it only returns the first 100 users from my domain. I have about 1000 users total, perhaps a few more. Can I pull all of them? If not, can I at least increase the limit beyond 100? And/or how can I limit my query to a particular Organizational Unit?
My full code below:
function writeToSpreadsheet(){
var values = [];
var users = AdminDirectory.Users.list({domain:'klht.org'}).users; //example: ignitesynergy.com
for (var i=0; i<users.length; i++){
values.push([users[i].name.fullName, users[i].primaryEmail]); //Look in the docs or use auto complete to see what you can access
}
var spreadsheetID = '1JLDD2wm0_udmTn9ZHvdKhL_Ok3SvKYFqkBeiA1GdnYc';
SpreadsheetApp.openById(spreadsheetID).getSheets()[0].getRange(1, 1, values.length, values[0].length).setValues(values);
}
//Red indicates the places you need to use your info
回答1:
The maximum you can pull down is 500 – maxResults
Also add the orgUnitPath as part of a query field in your list call:
var users = AdminDirectory.Users.list({
domain: 'klht.org',
maxResults: 500,
query: "orgUnitPath=/OU"
}).users;
part of the returned object will be a nextPageToken
you can add this into a follow-on query or queries until you have all your users
var usersPage2 = AdminDirectory.Users.list({
domain: 'klht.org',
maxResults: 500,
query: "orgUnitPath=/OU",
pageToken: nextPageToken
}).users;
来源:https://stackoverflow.com/questions/34398021/directory-query-returns-only-100-users