|
|
Thread Tools | Display Modes |
|
#1
|
|
|
Big grins
|
Announcing: phpSmug - A PHP Wrapper to the SmugMug API
Ladies and gentlemen, may I introduce you to a new project of mine…
phpSmug is a PHP wrapper class for the SmugMug PHP API. Whilst there esentially isn't a need for the wrapper, the intention of this class is to allow PHP application developers to quickly and easily interact with the SmugMug API in their applications, without having to worry about the finer details of the API. phpSmug is written for PHP 4 and PHP 5, however PHP 4 support will be withdrawn at the end of the year when PHP 4 officially reaches the end of life, announced here, and then I’ll work on optimising this to take full advantage of PHP 5’s great features. Don’t worry, I will still keep the PHP 4 supporting version available for those who can’t move to PHP 5 immediately. phpSmug is based on the great work of Dan Coulter in phpFlickr. I intend on having two concurrently running versions of phpSmug - one for each version of the API versions SmugMug is currently supporting. phpSmug at the moment only supports the 1.2.0 API calls, but I’m in the process of creating a branch for the 1.2.1 API calls. <del>I'll update this thread when it's available.</del> Now I’ll let you in on a little secret - the reason I’ve created this class is I’m in the process of creating a gallery plugin for Wordpress (to be called SmugGal) that draws photos from SmugMug, very much like FAlbum draws photos from Flickr. When this is released (hopefully by 31 Oct ;-) ), it will use the 1.2.1 API. I've contributed a huge amount of my time and code to FAlbum (I'm the second largest contributor behind the main developer), and after numerous requests, am finally working on the an equivalent for SmugMug. To try and keep things simple, I’ve separated the API interaction code (phpSmug) from the gallery code (SmugGal). So, if you’re a PHP application developer, and need to interact with SmugMug, please feel free to use phpSmug and drop me line to let me know what you’re up to with this class. I'd really appreciate it is somone could add a link to phpSmug, just below Riyad Kalla's Java API link, on the wiki too. 13 Oct '07 - UPDATE: phpSmug 1.1.1, which supports rev 1.2.1 of the API ,is now available. At the moment, it only officially implements those methods detailed at http://dgrin.com/showthread.php?t=71887. The code is in place for ALL of the functions listed on the wiki, however some of the methods haven't been implemented in the API itself, so I've not tested these, so can't be sure they'll return the correct data. At the moment, these methods are commented out and will return "Not implemented in API yet". I'll update phpSmug 1.1.x as these methods become available. 28 Jan '08 - UPDATE: I've been a bit slack in updating this thread as I've released new revs of phpSmug. Here's a summary of recent updates: 1.0.5 / 1.1.3 - 27 Jan ‘08 - All login.with* methods now use HTTPS to ensure login information is encrypted (Ticket #14) 1.0.4 / 1.1.2 - 4 Jan ‘08 - Changing caching to ensure more consistent caching (Ticket #11) - Changed “response” database table field type to LONGTEXT to cater for larger amounts of data. (Ticket #12) - Fixed issue where apostrophes in cached data are not escaped correctly (Ticket #13) 9 Feb '08 - UPDATE phpSmug 1.0.6 / 1.1.4 now support the new security functionality. 10 Feb '08 - UPDATE Forgot to take into account the ImageKey returned by image_upload() and image_uploadFromURL(), and AlbumKey returned by album_create(). These functions now return an array holding the ID and key. Thanks to devbobo for pointing this out so quickly. 23 Feb '08 - UPDATE Made changes to the caching code to fix caching issue brought up by rolandk98 on this thread and to take into account 6 hour SessionID inactivity timeout. 26 Feb '08 - UPDATE Removed extra "}" from phpSmug 1.0.8. phpSmug 1.0.9 now available. 4 Mar '08 - UPDATE I've had a busy couple of afternoons quashing bugs and enhancing phpSmug further. This release sees the re-introduction of anonymous method call caching (Ticket #18), enableCache() now checks cache directory is writeable (Ticket #19), die_on_error is now acknowledged consistently. If die_on_error is NOT set, it's up to the application developer to check getErrorCode and getErrorMessage after each method call. (Ticket #20), I've added clearCache() function to easily empty the cache. (Ticket #22) and I've Stopped caching the results of failed method calls when die_on_error is set. (Ticket #23). phpSmug 1.0.10 and phpSmug 1.1.7 now available Enjoy. _____________________________________ Colin Seymour Personal Blog | Tech Blog Last edited by lildude; Mar-04-2008 at 08:28 AM. |
|
|
|
|
#2
|
|
|
Grin there, done that
|
Sounds cool!
__________________
|
|
|
|
|
#3
|
|
|
SmugMug CEO & Chief Geek
|
Awesome!
Blogged, posted to the mailing lists, and linked on the wiki. Make sure you enter this in the contest, too, once it's got 1.2.1 support. :) Thanks! |
|
|
|
|
#4
|
|
|
Big grins
|
Will do, thanks.
|
|
|
|
|
#5
|
|
|
Big grins
|
Support for 1.2.1 of API now available.
phpSmug 1.1.1, which supports rev 1.2.1 of the API ,is now available. At the moment, it only officially implements those methods detailed at http://dgrin.com/showthread.php?t=71887.
The code is in place for ALL of the functions listed on the wiki, however some of the methods haven't been implemented in the API itself, so I've not tested these, so can't be sure they'll return the correct data. At the moment, these methods are commented out and will return "Not implemented in API yet". I'll update phpSmug 1.1.x as these methods become available. |
|
|
|
|
#6
|
|
|
quiet annoyingly pedantic
|
I'm liking where this is going... And am pretty excited at the thought of SmugGal since I'm fast becoming a WordPress convert... Thanks for your time and effort, I'll be watching this!
__________________
[FONT=Trebuchet MS]Canon EOS [/FONT][FONT=Trebuchet MS]500D [/FONT][FONT=Trebuchet MS]([/FONT][FONT=Trebuchet MS]Kiss X3[/FONT][FONT=Trebuchet MS])[/FONT][FONT=Trebuchet MS] 85mm f/1.8, 17-50 + 28-75m[/FONT] [FONT=Trebuchet MS]f/2.8 [/FONT][FONT=Trebuchet MS]lenses[/FONT] [FONT=Trebuchet MS]iMac 24" 2.8 GHz Intel Core 2 Extreme, 4Gb RAM, OSX 10.5.7 http://encosion.com/ | http://encosion.smugmug.com/ [/FONT] |
|
|
|
|
#7
|
||
|
Big grins
|
Bit of a delay on SmugGal
Quote:
I won't get into the details just yet, but watch this space. |
|
|
|
||
|
#8
|
|
|
Beginner grinner
|
Awesome!
I've been procrastinating about finishing SmugSync (rsync for SmugMug), and now this and the h.264 support is going to push me over the top. Cool!
-Dan |
|
|
|
|
#9
|
|
|
Big grins
|
Revs 1.0.5 and 1.1.3 now available.
Bumped for new revs. Revs 1.0.5 and 1.1.3 now available.
|
|
|
|
|
#10
|
||
|
Road Trip!
|
Quote:
__________________
www.brettmickelson.com |
|
|
|
||
|
#11
|
||
|
Big grins
|
Quote:
I envisage it'll be ready within the next month or so (provided work doesn't get too crazy). |
|
|
|
||
|
#12
|
|
|
Big grins
|
Bump for new rev
|
|
|
|
|
#13
|
||
|
technicolored
|
Quote:
Thanks for being so proactive with implementing the new security features Just had a quick look through the code and I have two suggestions, I think you need to return... - the AlbumKey with the albums_create function - the ImageKey with the images_upload and images_uploadFromURL functions Cheers, David |
|
|
|
||
|
#14
|
||
|
Big grins
|
Quote:
Thanks for spotting this so quickly. Cheers, Colin |
|
|
|
||
|
#15
|
|
|
tera grins
|
caching issues
phpsmug is great, we were able to port an application writen for flickr with relative ease. But.
but is the bellow described a bug?? If caching is enabled, and you login anonymously the first time, then, within the same session you login withpassword, the cache value of the anonymouse login is returned. why would you login anonymously and then with password??? I wrote a web application that uses smugmug api and gives the user the ability to retrieve the list of their public albums by loging in with just their nickname [to get public album] or username and password to get all albums. (most people will try out just nickname login before just pluging in their username and password on a new website right!!!) but if they like it and feel comfortable, they would like to retrieve all their albums, public or unlisted. so if within the same session they had loged in with just nickname (i.e. anonymouse) the second login using withpassword will not work or will just return the cache value of the anonymouse login. is it a bug? or my error? if i dissable cashing everything works just fine thx roland |
|
|
|
|
#16
|
||
|
Big grins
|
Quote:
Glad to hear you've found it useful. I'd love to see what you've done with phpSmug - I can even add a link to my project page if you want. I can shamefully say this is a bug, and without even looking at the code I know why. I made a change to the caching a while back to try make caching simpler (also because of something I couldn't determine from the session ID at the time, see below), however I have to admit I didn't think of the scenario you've detailed, and by the fact it's taken so long to come to light, I don't think anyone else did either I'll reverse my change in the next rev (I'll try get this out today). In the mean time you can reverse the change I made by commenting out the: Code:
$request['SessionID'] = ''; // Unset SessionID This has two catches: 1. You MUST enable caching BEFORE calling any of the login_* functions, else you'll end up generating a new session with every login_* call, and subsequently every single API call, which kind of defeats the point of caching. 2. I still don't know (I've just posted my query here), how long each session is valid for. I've found that if a session isn't used for a while (somewhere between 8 and 24 hours), it's ID is no longer valid, however if it's regularly used, eg every 2 hours, it seems to last indefinitely. Once I know the answer to this last catch, I'll update the code. It's essential I know this as this has an effect on the maximum cache value someone can use with phpSmug. For example, if the session inactivity timeout is 8 hours, and a developer sets the cache expire to 24 hours, we hit a problem if a user logs in, lists their albums and then doesn't come back for 20 hours. Their session ID would be invalid, but the cache would still be valid, and thus will still be used. My previous change removed the need to know this as the session ID was never stored. I'll update this thread when I know the sessionID inactivity timeout and when I've updated my code. Thanks for pointing this out. Cheers, Colin |
|
|
|
||
|
#17
|
||
|
Big grins
|
Quote:
I'm going to have to do a bit of testing with the current caching methods to see if I can come up with a more efficient method. If possible, I don't want to pummel the SmugMug API servers every 6 hours if possible - it puts unnecessary load on the servers and potentially slows the apparent performance of applications using phpSmug. Watch this space. |
|
|
|
||
|
#18
|
|
|
Big grins
|
Hi Roland
I've been thinking about this some more, and if you don't make the changes I specified in an earlier post, thus leaving the code as it is, you can get the correct behaviour, with caching enabled, by NOT using the nickname in the albums_get() call after logging in with a password. The nickname isn't needed once you've logged in as it defaults to the user anyway. It's only really needed when viewing other people's albums, which you can only do anonymously anyway. So if we put this into code, you should find the $anon_albums will show only the public albums and the $all_albums will show the unlisted and public albums: Code:
<?php
require_once("phpSmug.php");
$f = new phpSmug($APIKEY, "Testing phpSmug");
$f->enableCache("db", "mysql://$USER:$PASSWD@$HOST/$DB");
$f->login_anonymously();
$anon_albums = $f->albums_get("$NICKNAME");
$f->login_withPassword("$EMAIL", "$PASSWORD");
$all_albums = $f->albums_get();
echo "<pre>";
print_r($anon_albums);
echo "============================";
print_r($all_albums);
echo "</pre>";
?>
I'm reluctant to start caching the SessionID as part of the request (it's still cached in the response) due to the 6 hour inactivity timeout. |
|
|
|
|
#19
|
|
|
Big grins
|
Ignore my previous post. I've just thought of a problem with this strategy. If you left things inactive for 6 hours between calling the login_with*() and the first time you called albums_get(), you'd hit the 6 hour SessionID inactivity timeout and your albums_get() will fail.
I'll re-architect the caching algorithm to take this SessionID inactivity timeout into account, and still allow for a custom cache timeout of greater than 6 hours. I should have something for you tomorrow. |
|
|
|
|
#20
|
||
|
tera grins
|
Quote:
My site that is using phpSmug is http://www.terasnaps.com/ and how I am using phpSmug can be viewed in the flv video here http://www.terasnaps.com/howtovideos/smugmughowto.php . I will post a more complete description in the appropriate section of this forum later. But basicaly is retreives your smugmug photos, does face detection, recognition and provides you with the ability to organize your family photos by the people who are in the photos. It is calibrated to detect faces that are the subject of the picture as opposed to background people. So its ideal for family photo organization as opposed to artistic photos. Terasnaps also creates an anonymouse browsing envirment where tags and nicknames are not displayed at all and the bowsing is based in familiarity with the individuals in the photos. Terasnaps is also an image combining network that can combine images of particular individual accross multiple terasnaps accounts and combine same events accross multiple terasnaps account. So check it out and let me know, I just released the smugmug integration and wanted to let you know first with many thanks. testers are welcomed. Feel free to add my websites link to your project pages if you wish. Again Many Thanks Roland |
|
|
|
||
| Tell The World! | |
| Thread Tools | |
| Display Modes | |
|
|