开发者

Retrieve user account

开发者 https://www.devze.com 2022-12-19 07:30 出处:网络
I used the following coding to display user accounts in my domain.But in that coding it display only first 100 records.But in my domain nearly 500 users account.I don\'t know what problem in this codi

I used the following coding to display user accounts in my domain.But in that coding it display only first 100 records.But in my domain nearly 500 users account.I don't know what problem in this coding

import java.net.URL;
import java.util.List;

import com.google.gdata.client.appsforyourdomain.UserService;
import com.google.gdata.data.appsforyourdomain.provisioning.UserEntry;
import com.google.gdata.data.appsforyourdomain.provisioning.UserFeed;

public class Readuser {
       public int i3;
       public  String rn[]=new String[100];



    public void read(){
        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");
                User开发者_JS百科Feed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);
                List<UserEntry> entries = resultFeed.getEntries();

                for(i3=0; i3<entries.size(); i3++) {
                  UserEntry entry = entries.get(i3);
                  rn[i3]=  entry.getTitle().getPlainText();
                  System.out.println(rn[i3]);
                }
                System.out.println("\nTotal Entries: "+entries.size());
              }
             catch(Exception e) { System.out.print(e);}
         }

    public static void main(String args[])
    {
    Readuser ru=new Readuser();
    ru.read();
    }
}


You only allocate 100 entries.

public  String rn[]=new String[100];


Hint from your code : public String rn[]=new String[100];

Do you really need to have i3 and rn as class members ? Do you really need rn ? A List seems more comfortable as an Object than a String[].


There is no need for the string array (String[]). Arrays are fixed size; and in this case you have allocated 100 "slots" for Strings, and when You try to assign a string to position 100 ( you know, the 101:th string) it fails.

You catch an exception in the end. Print the stack trace to find out whats going on

catch(Exception e) { 
    e.printStackTrace();
} 

Learn to read it an find out what is says... However you should not catch the exception in this method. It is better to abort whatever the program was doing. Catch it in your main method - just printing or logging it is fine, so that you can correct the programming error.

Anyway; The result you get is a List of user entries. Lists are part of the (java.util)collections framework. Collections have a lot of features; in this case you want to iterate over all entries in the list. You can do this by using the iterator() method -read the javadoc...OR you can use for-loop syntactic sugar for doing this:

for( UserEntry user : entries ) {
    // user is the current UserEntry
    System.out.println(user.getTitle().getPlainText()); 
} 

The variables i3 and rn are no good... They shouldn't be class variables, and if you need "temporary" variables, define them close to where you are going to use them.

As for naming of variables, a name like "entry" is less useful than "user". Actually a class called UserEntry should probably be called just User, but I don't know about this API, so...

0

精彩评论

暂无评论...
验证码 换一张
取 消