Pergunta

Eu criei um domínio nesse domínio i criado quase 500 accounts.I usuário deseja recuperar todos os usuários em meu domínio .so que eu uso a seguinte codificação para recuperar todos os usuários no meu domain.But em que a codificação i exibida apenas o primeiro 100 users.And também que exibir entradas totais de usuário 100.I não sei o problema neste codificação.

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

O problema neste codificação?

Foi útil?

Solução

A lista de usuários é retornado em um feed Atom. Este é um alimento para animais paginada, com um máximo de 100 entradas por página. Se houver mais entradas na alimentação, em seguida, haverá um átomo: elemento de ligação com um atributo rel = "next", apontando para a página seguinte. Você precisa continuar a seguir estas ligações até que não haja mais páginas 'Seguinte'.

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

O código será algo parecido com:

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());
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top