2010-02-05 77 views
3

我在该域中创建了一个域,我创建了近500个用户帐户。我想检索域中的所有用户.so我使用以下编码检索我的所有用户domain.But在那个编码我只显示前100个用户。并且它也显示总用户条目100.我不知道在这个编码中有什么问题。如何检索我的域中的所有用户

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.AuthenticationException; 
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(); 
     } 
    } 
    } 

这个编码有什么问题?

回答

2

用户列表以原子提要返回。这是一个分页Feed,每页最多有100个条目。如果Feed中有更多条目,则会有一个具有rel =“next”属性的atom:link元素,指向下一页。你需要继续关注这些链接,直到没有更多'下一页'的页面。

参见:http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#Results_Pagination

的代码看起来是这样的:

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()); 
相关问题