The following uses the user service get entry to get information about a
user. If the user doesn't exist the following exception it thrown
AppsForYourDomainErrorCode.EntityDoesNotExist.

In other locations I just try to create a user and if they already exist I
update the user instead. The error AppsForYourDomainErrorCode.EntityExists
is thrown if you try to create a user and that user exists.

   public String doesUsernameExist(String username) {
          if(username == null || username.length()==0){
              System.out.println( "Username was blank of null so no check of
Apps was attempted.");
              return "";
          }else{
          try{
       System.out.println("Retrieving user '" + username + "'.");

        URL retrieveUrl = new URL(domainUrlBase + "user/" + SERVICE_VERSION
+ "/" + username);
        UserEntry ue = userService.getEntry(retrieveUrl, UserEntry.class);
          } catch (AppsForYourDomainException e) {

if(e.getErrorCode()==AppsForYourDomainErrorCode.EntityDoesNotExist ){
                    System.out.println( "Username " + username + " was not
found");
                    return "";
                }else{
                    Notify.error("AppsForYourDomainException in
doesUsernameExist. " + e.getLocalizedMessage() );
                e.printStackTrace();
                }
            } catch (ServiceException e) {
                Notify.error("Service Exception in doesUsernameExist. " +
e.getLocalizedMessage() );
                e.printStackTrace();
                return "";
            } catch (IOException e) {
                Notify.error("IOException in doesUsernameExist. " +
e.getLocalizedMessage() );
                e.printStackTrace();
                return "";
            }
            return username;
          }
      }

On Mon, Nov 17, 2008 at 4:24 PM, Abraham Segura <[EMAIL PROTECTED]>wrote:

> Hi i already do a developer with java but i have a problem with my
> development so i need to check if a user a username is already in google
> when i am creating a new know so if you have an example for this development
> i will be nice, so i hope you can help me people.
>
> Regards
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Apps APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to