Examples

The basic design of the kallasoft SmugMug Java API is to map a single Java class to every method defined in the SmugMug JSON API. For example, if you want to login to SmugMug using the withPassword method, then you want to use the WithPassword class to do it.

Below are a few snippets of example code, to give you a real-world example of how this API works.

Anonymous Login

/* Create an instance of the Anonymously method */
Anonymously anonymously = new Anonymously();
 
/* Execute the login, passing the arguments provided */
Anonymously.AnonymouslyResponse response =
        anonymously.execute(SECURE_SERVER_URL, API_KEY);
 
/* Check if there was an error with the login. If nothing went wrong,
 * print out the full response. */
if (response.isError()) {
    System.out.println("Login Failed, message: " + response.getError().getMessage());
} else {
    System.out.println("Login Successful, Session ID: " + response.getSessionID());
}

Username & Password Login

/* Create an instance of the WithPassword method */
WithPassword withPassword = new WithPassword();
 
/* Execute the login, passing the arguments provided */
WithPassword.WithPasswordResponse response =
        withPassword.execute(SECURE_SERVER_URL, API_KEY, USERNAME, PASSWORD);
 
/* Check if there was an error with the login. If nothing went wrong,
 * print out the full response. */
if (response.isError()) {
    System.out.println("Login Failed, message: " + response.getError().getMessage());
} else {
    System.out.println("Login Successful, Session ID: " + response.getSessionID());
    System.out.println("\tUser ID: " + response.getUserID());
    System.out.println("\tPassword Hash: " + response.getPasswordHash());
    System.out.println("\tNick Name: " + response.getNickName());
    System.out.println("\tDisplay Name: " + response.getDisplayName());
    System.out.println("\tAccount Type: " + response.getAccountType());
    System.out.println("\tUpload File Size Limit: " + response.getFileSizeLimit());
}