Kallasoft API installation

aostilesaostiles Registered Users Posts: 3 Beginner grinner
Hello, I have eclipse set up for java development. However, I am new to writing java applications, and I am not sure how to use the kallasoft SmugMug Java API in eclipse. How would I use one of the methods in the API? I know I would have to import the class at the beginning of the code, but what I'm trying to say is how would eclipse know where to find the kallasoft api? Thanks in advance.

Comments

  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited August 20, 2009
    Hey Andrew,

    Standby, I'll get Riyad to answer personally.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • rkallarkalla Registered Users Posts: 108 Major grins
    edited August 20, 2009
    Andrew,

    Getting started with Java programming can be a bit daunting. The first thing you need to do is right-click on your project, and go to Properties > Java Build Path > Libraries, click Add and add the API JAR.

    The JAR is a bundle of all the classes, putting it on the build path like that allows Eclipse to find those classes for you.

    Once you've done that, then you can literally work with any of the SmugMug methods by name -- as the kallasoft API maps the methods exposed by SmugMug to Java classes pretty much 1:1, here's an example:
    http://www.kallasoft.com/smugmug-java-api/examples/

    So the SmugMug API has a WithPassword login call that you use to login with a password, so in the Java API, you have the same. All the arguments are defined for you so you just create a new instance of WithPassword and use the execute method on it to call it.

    The only part that might not be straight forward is the "apiKey", you have to login to your SmugMug account and generate one from the Control Panel.

    I've created an example project for you here:
    http://www.kallasoft.com/downloads/smugmug-java-api-example-project.zip

    that you can import into Eclipse (File > Import > Existing Project > Archive...) and start immediately. It includes the libraries for the most current release of the API, and an example class that looks like this:
    package com.kallasoft.smugmug.example;
    
    import com.kallasoft.smugmug.api.json.v1_2_1.APIVersionConstants;
    import com.kallasoft.smugmug.api.json.v1_2_1.login.WithPassword;
    
    public class WithPasswordExample {
        public static void main(String[] args) {
            /*
             * Enter your API key here, you can create one from the SmugMug Control
             * Panel after logging in
             */
            String apiKey = "";
    
            /* Enter your username and password for your SmugMug account */
            String username = "";
            String password = "";
    
            /* Create an instance of the WithPassword method */
            WithPassword withPassword = new WithPassword();
    
            /* Execute the login, passing the arguments provided */
            WithPassword.WithPasswordResponse response = withPassword.execute(
                    APIVersionConstants.SECURE_SERVER_URL, apiKey, 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());
            }
        }
    }
    

    Let me know if you have any questions.
  • aostilesaostiles Registered Users Posts: 3 Beginner grinner
    edited August 21, 2009
    Thank you David, and thanks for all the help Riyad. I'm about to try it out but it seems pretty straightforward. Once again, thanks a lot :D
Sign In or Register to comment.