View Full Version : API auth: unattended command-line access
TerenceKearns.com
May-31-2010, 07:44 PM
Hi all,
I am a PHP developer who has never used the smugmug API before.
I want to write a command-line PHP script which can authenticate to smugmug, upload designated files to a designated album and then exit. The script is to run from crontab (or task scheduler I guess).
1) Can it be done?
2) What is the Authentication procedure. ie. How do I get a session ID?
Thanks.
TerenceKearns.com
May-31-2010, 08:40 PM
Okay I found smugmug.login.withHash in version 1.2.0 of the API
I didn't find it before because I just assumed the entire API would be in the latest version of the API (1.2.2)
Can someone tell me how the password is hashed?
The API documentation leaves no clues.
devbobo
Jun-01-2010, 12:09 AM
if you call smugmug.login.withPassword, the PasswordHash ( and UserID) are returned. if you record these values, you will be able to call smugmug.login.withHash from your cron job.
Cheers,
David
TerenceKearns.com
Jun-01-2010, 04:21 AM
Thanks for that.
I retrieve it.
TerenceKearns.com
Jun-01-2010, 07:16 AM
Okay I am getting
<title>413 Request Entity Too Large</title>
</head><body>
<h1>Request Entity Too Large</h1>
The requested resource<br />/photos/xmlrawadd.mg<br />
does not allow request data with PUT requests, or the amount of data provided in
the request exceeds the capacity limit.
</body>
I'm using the following code
$data = array("name" => "the file", "file" => "@".$ImgFile);
$arrHeaders = array();
$arrHeaders[] = "Content-MD5: ".md5_file($ImgFile);
$arrHeaders[] = "Content-length: ".filesize($ImgFile);
$arrHeaders[] = "X-Smug-SessionID: ".$this->sid;
$arrHeaders[] = "X-Smug-Version: ".API_VERSION;
$arrHeaders[] = "X-Smug-ResponseType: PHP";
$arrHeaders[] = "X-Smug-AlbumID: ".$this->aid;
$arrHeaders[] = "X-Smug-FileName: ".basename($ImgFile);
$arrHeaders[] = "X-Smug-Keywords: ".$argKeyWords;
$cl = curl_init(RAW_UPLOAD_URL)
OR $this->log->error("Could not initiate image upload.");
curl_setopt($cl,CURLOPT_USERAGENT,SMUG_USER_AGENT) ;
curl_setopt($cl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($cl,CURLOPT_HTTPHEADER,$arrHeaders);
curl_setopt($cl,CURLOPT_POST,1);
curl_setopt($cl,CURLOPT_POSTFIELDS,$data);
$fp=fopen($ImgFile,"r");
curl_setopt($cl,CURLOPT_INFILE,$fp);
curl_setopt($cl,CURLOPT_INFILESIZE,filesize($ImgFi le));
curl_setopt($cl,CURLOPT_UPLOAD,1);
$res = curl_exec($cl);
fclose($fp);
curl_close($cl);
The whole lot is in a try/catch block and no exception is being thrown.
RAW_UPLOAD_URL = http://upload.smugmug.com/photos/xmlrawadd.mg
The size of the image is about 100kb.
devbobo
Jun-01-2010, 06:06 PM
RAW_UPLOAD_URL = http://upload.smugmug.com/photos/xmlrawadd.mg
are you posting or putting to this url ?
TerenceKearns.com
Jun-01-2010, 06:41 PM
are you posting or putting to this url ?
That is correct.
According to curl, it should be POSTing, not PUTting because I set the posting flag like so...
curl_setopt($cl,CURLOPT_POST,1);
1 is equivalent to TRUE in this case...
devbobo
Jun-01-2010, 07:17 PM
That is correct.
According to curl, it should be POSTing, not PUTting because I set the posting flag like so...
curl_setopt($cl,CURLOPT_POST,1);
1 is equivalent to TRUE in this case...
Can you please post or PM your script...obviously with sensitive stuff like API Keys and PasswordHash removed so i can run this locally and debug if required ?
Thanks,
David
TerenceKearns.com
Jun-03-2010, 05:05 AM
Can you please post or PM your script...obviously with sensitive stuff like API Keys and PasswordHash removed so i can run this locally and debug if required ?
Thanks,
David
done
TerenceKearns.com
Jun-07-2010, 11:21 AM
The "Entity too large" thing is a separate issue so I am going to move it to a new thread.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.