How to retrieve all users in my domain
I created one domain in that domain i created nearly 500 user accounts.I want to retrieve all the users in my domain .so that i use the following coding to retrieve all the users in my domain.But in that coding i displayed only first 100 users.And also it display total user entries 100.I dont know what problem in this coding.
import com.google.gdata.client.appsforyourdomain.UserService;
import com.google.gdata.data.appsforyourdomain.provisioning.UserEntry;
import com.google.gdata.data.appsforyourdomain.provisioning.UserFeed;
import com.google.gdata.util.AuthenticationExcep开发者_如何学运维tion;
import com.google.gdata.util.ServiceException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
/**
* This is a test template
*/
public class AppsProvisioning {
public static void main(String[] args) {
try {
// Create a new Apps Provisioning service
UserService myService = new UserService("My Application");
myService.setUserCredentials(admin,password);
// Get a list of all entries
URL metafeedUrl = new URL("https://www.google.com/a/feeds/"+domain+"/user/2.0/");
System.out.println("Getting user entries...\n");
UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);
List<UserEntry> entries = resultFeed.getEntries();
for(int i=0; i<entries.size(); i++) {
UserEntry entry = entries.get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}
System.out.println("\nTotal Entries: "+entries.size());
}
catch(AuthenticationException e) {
e.printStackTrace();
}
catch(MalformedURLException e) {
e.printStackTrace();
}
catch(ServiceException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
}
what problem in this coding?
The list of users is returned in an atom feed. This is a paged feed, with a maximum of 100 entries per page. If there are more entries in the feed then there will be an atom:link element with a rel="next" attribute, pointing at the next page. You need to keep following these links until there are no more 'next' pages.
See: http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#Results_Pagination
The code will look something like:
URL metafeedUrl = new URL("https://www.google.com/a/feeds/"+domain+"/user/2.0/");
System.out.println("Getting user entries...\n");
List<UserEntry> entries = new ArrayList<UserEntry>();
while (metafeedUrl != null) {
// Fetch page
System.out.println("Fetching page...\n");
UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);
entries.addAll(resultFeed.getEntries());
// Check for next page
Link nextLink = resultFeed.getNextLink();
if (nextLink == null) {
metafeedUrl = null;
} else {
metafeedUrl = nextLink.getHref();
}
}
// Handle results
for(int i=0; i<entries.size(); i++) {
UserEntry entry = entries.get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}
System.out.println("\nTotal Entries: "+entries.size());
精彩评论