API use examples...?
oxy8384
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
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
0
Comments
[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]
Perhaps start with what you are trying to do, and we will go from there.
Cheers,
David
SmugMug API Developer
My Photos
figbug,
That is exactly it - just trying to understand the method.
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
SmugMug API Developer
My Photos