API auth: unattended command-line access
TerenceKearns.com
Registered Users Posts: 13 Big grins
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.
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.
0
Comments
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.
Cheers,
David
SmugMug API Developer
My Photos
I retrieve it.
[HTML]<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>[/HTML]
I'm using the following code
[PHP]
$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($ImgFile));
curl_setopt($cl,CURLOPT_UPLOAD,1);
$res = curl_exec($cl);
fclose($fp);
curl_close($cl);
[/PHP]
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.
are you posting or putting to this url ?
SmugMug API Developer
My Photos
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
SmugMug API Developer
My Photos
done