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


0 Comments For This Post
3 Trackbacks For This Post
October 21st, 2007 at 5:23 pm
[...] simple examples page may give you a better idea of how to use the API out of the gate (I will be adding more examples [...]
March 24th, 2008 at 5:29 pm
[...] updated examples for logging in were posted to the Examples Page. There should be a pack of simple examples that are released with the Beta 5 release here in the [...]
May 17th, 2008 at 8:58 am
[...] You can see this in action (as an example) over on the kallasoft SmugMug Java API Examples page. [...]
Leave a Reply