问题描述
我从借用了代码,以从我的Google下载目录数据域转换为电子表格。我在代码中修改的所有代码都是用OpenByID替换OpenByURL,因为参数错误无效。现在它可以工作,但它只返回来自我的域的前100位用户。我总共有大约1000个用户,也许还有几个用户。我可以把他们全部拉出来吗?如果不是,我可以至少增加超过100的限制吗?和/或如何限制我的查询到一个特定的组织单位?
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
推荐答案
您可以拉下的最大值为500 -
The maximum you can pull down is 500 – maxResults
还要在列表调用中添加orgUnitPath作为查询字段的一部分:
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;
返回对象的一部分将是 nextPageToken
您可以将其添加到后续查询或查询中,直到您拥有所有用户为止。
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;
这篇关于目录查询仅返回100个用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!