Examples for a newbie

OppsOpps Registered Users Posts: 160 Major grins
I'm interested in writing an app that would work with smugmug, but since I'm new to the SmugMug API I'm interested in examples of how to manipulate the galleries etc. I couldn't find anything but I might be looking in the wrong place.

Also, if/when I get as far as to actually start manipulating the archives what is the best way of testing? I mean it feels a bit frightening to do this on my real account, do I create another "try-it" account and do the testing there or do I do this in some other way?
--
Jan Erik Moström

Comments

  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited November 24, 2008
    well, it really depends on what language you are going to write your app in.
    David Parry
    SmugMug API Developer
    My Photos
  • OppsOpps Registered Users Posts: 160 Major grins
    edited November 25, 2008
    devbobo wrote:
    well, it really depends on what language you are going to write your app in.

    To be honest I haven't decided yet, what I'm unsure about is how the actual communication work, how a request should look like, how an answer look like etc. I know that these are pretty basic question but I've no experience from doing "remote access" like this and would like see a few examples just to get going. Language ... well examples in Objective-C, REALBasic, Java, Python, Perl, C, C++, etc are OK with me (but preferable not Windows only since I'm not using Windows)
    --
    Jan Erik Moström
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited November 26, 2008
    Here's a perl sample for logging in....
    use LWP;
    use JSON;
    
    ($stat, $result) = call('method' => 'smugmug.login.withPassword',
                        'EmailAddress' => '<insert nickname or email address>',
                        'Password' => '<insert password>',
                        'APIKey' => '<insert API key>');
                            
    if($stat eq 'ok') {
        my $session = $result->{'Login'}->{'Session'}->{'id'};
    }
    
    sub call {
        my %params = @_;
        my $baseURL = "api.smugmug.com/services/api/json/1.2.2?";
        
        my $requestURL = (${params}{'method'} =~ m/login/ ? "https" : "http")."://".$baseURL;
        
        for my $key (keys %params ) {
          $requestURL .= "$key=".${params}{$key}."&";
        }
           
        my $browser = LWP::UserAgent->new;
        my $response = $browser->get($requestURL);
        
        if(!$response->is_success()) {
            dump('retrying....');
            $response = $browser->get($requestURL);
        }
        
        my $json = new JSON(unmapping =>1);
        my $result = $json->jsonToObj($response->content);
    
        return ($result->{'stat'}, $result);
    }
    
    
    David Parry
    SmugMug API Developer
    My Photos
  • OppsOpps Registered Users Posts: 160 Major grins
    edited November 27, 2008
    Thanks, I'll play around
    --
    Jan Erik Moström
Sign In or Register to comment.