2010-02-05 78 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()); 
相關問題