0

I am trying to pull about 20,000 users from my Google domain. However, i know that Google only has a limit of about 500 users for a pull request. I know about the pageToken stuff, but the documentation for it online is terrible. Can someone show me how to use the pageToken? Please keep in mind i am using the google client libraries. This is what my code looks like so far:

@Test 
public void paginationTest() throws IOException, NullPointerException,      GeneralSecurityException { 
try { 


Directory directory = GCAuthentication.getDirectoryService("xxx", "vvv", dddd);
Directory.Users.List list = directory.users().list().setOrderBy("email").setMaxResults(500).setDomain("dev.royallepage.ca");

do { 
com.google.api.services.admin.directory.model.Users users = list.execute();
java.util.List<User> uL = users.getUsers(); 
//uL.addAll(users.getUsers());
//list.setPageToken(list.getPageToken()); 
System.out.println(uL.size());
}while (list.getPageToken() != null && list.getPageToken().length() > 0); 

}catch(NullPointerException e) { 

}

}

Please advise what i am doing wrong! Thanks,

Mesam

MesamH
  • 91
  • 1
  • 2
  • 6

1 Answers1

1

You will have to create a function that will get the pageToken variable then call another request including the nextPageToken.

Use the pageToken query string for responses with large number of groups. In the case of pagination, the response returns the nextPageToken property which gives a token for the next page of response results. Your next request uses this token as the pageToken query string value.

Sample Code Request:

GET https://www.googleapis.com/admin/directory/v1/users
?domain=primary domain name&pageToken=token for next results page
&maxResults=max number of results per page
&orderBy=email, givenName, or familyName
&sortOrder=ascending or descending
&query=email, givenName, or familyName:the query's value*

Hope this helps!

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91