質問

私は私がaccounts.Iが自分のドメイン内のすべてのユーザーを取得する約500のユーザーを作成し、そのドメインでのドメインを作成し、私は表示されている符号化で私domain.But内のすべてのユーザーを取得するには、次のコードを使用することの.so最初の100 users.Andもそれは100.Iは、この符号化においてどのような問題を知らない。

総ユーザーエントリを表示します
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();
      }
    }
  }

このコーディングでは何の問題?

役に立ちましたか?

解決

ユーザーのリストは、Atomフィードで返されます。これは、ページあたり100のエントリの最大で、ページングフィードです。次のページを指差し、REL =「次」属性を持つ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());
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top