3

そのドメインに1つのドメインを作成し、500近くのユーザーアカウントを作成しました。ドメイン内のすべてのユーザーを取得したいので、次のコーディングを使用してドメイン内のすべてのユーザーを取得します。しかし、そのコーディングでは、最初の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();
      }
    }
  }

このコーディングにはどのような問題がありますか?

4

1 に答える 1

2

ユーザーのリストはAtomフィードで返されます。これはページフィードであり、1ページあたり最大100エントリです。フィードにさらにエントリがある場合は、次のページを指す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());
于 2010-02-06T00:57:49.273 に答える