API use examples...?

oxy8384oxy8384 Registered Users Posts: 389 Major grins
This is really basic and I haven't been able to find this in the API documentation:
Are there just simple examples of how to make an API call and how to retrieve the results in the various formats (I'm a PHP user, myself). I 'get' all the pieces, but I just don't know how to the interface works.:scratch:rolleyes

Thanks,

Bill

Comments

  • figbugfigbug Registered Users Posts: 41 Big grins
    edited July 7, 2007
    I'm not exactly sure what you want, but here is an example of how to login, list all albums and their category and then log out, using php.

    [PHP]// login in to smugmug
    $base = 'https://api.smugmug.com/hack/php/1.2.0/';
    $query_string = '';
    $params = array(
    'method' => "smugmug.login.withPassword",
    'EmailAddress' => 'email@email.com',
    'Password' => 'password',
    'APIKey' => 'apikey'
    );
    foreach ($params as $key => $value) {
    $query_string .= "$key=" . urlencode($value) . "&";
    }
    $url = "$base?$query_string";
    $out = file_get_contents($url);
    $res = unserialize($out);

    $sessionId = $res;

    // get all the albums
    $base = 'https://api.smugmug.com/hack/php/1.2.0/';
    $query_string = '';
    $params = array(
    'method' => "smugmug.albums.get",
    'Heavy' => '0',
    'SessionID' => $sessionId
    );
    foreach ($params as $key => $value) {
    $query_string .= "$key=" . urlencode($value) . "&";
    }
    $url = "$base?$query_string";
    $out = file_get_contents($url);
    $res = unserialize($out);

    $albums = $res;
    usort($albums, sortFunc);

    foreach ($albums as $album) {
    $title = $album;
    $id = $album;
    $cat = $album;

    echo "$title - $cat<br>";
    }

    // log out of smugmug
    $base = 'https://api.smugmug.com/hack/php/1.2.0/';
    $query_string = '';
    $params = array(
    'method' => "smugmug.logout",
    'SessionID' => $sessionId
    );
    foreach ($params as $key => $value) {
    $query_string .= "$key=" . urlencode($value) . "&";
    }
    $url = "$base?$query_string";
    $out = file_get_contents($url);
    [/PHP]
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited July 7, 2007
    G'day Bill,

    Perhaps start with what you are trying to do, and we will go from there.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • oxy8384oxy8384 Registered Users Posts: 389 Major grins
    edited July 7, 2007
    This is a good start...
    figbug,
    That is exactly it - just trying to understand the method.thumb.gif

    devbobo,
    Don't have a specific app in mind, yet. I was wondering how hard it would be to duplicate some SM functions like daterange.mg and popular.mg with enhanced sorting capability and/or an option to limit the number of images returned, so folks could do like a top 10, rather than just 'most popular'...

    For now, I need to go implement the basic interface and start exploring the results.

    Thanks a ton!

    Bill
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited July 7, 2007
    oxy8384 wrote:
    figbug,
    That is exactly it - just trying to understand the method.thumb.gif

    devbobo,
    Don't have a specific app in mind, yet. I was wondering how hard it would be to duplicate some SM functions like daterange.mg and popular.mg with enhanced sorting capability and/or an option to limit the number of images returned, so folks could do like a top 10, rather than just 'most popular'...

    For now, I need to go implement the basic interface and start exploring the results.

    Thanks a ton!

    Bill

    Bill,

    Your best bet would be to look at feeds. At present, popular and recent photos aren't searchable via the API.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
Sign In or Register to comment.