Directory query returns only 100 users

空扰寡人 提交于 2019-12-11 00:19:34

问题


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

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