API auth: unattended command-line access

TerenceKearns.comTerenceKearns.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.

Comments

  • TerenceKearns.comTerenceKearns.com Registered Users Posts: 13 Big grins
    edited June 1, 2010
    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.
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited June 1, 2010
    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
    David Parry
    SmugMug API Developer
    My Photos
  • TerenceKearns.comTerenceKearns.com Registered Users Posts: 13 Big grins
    edited June 1, 2010
    Thanks for that.
    I retrieve it.
  • TerenceKearns.comTerenceKearns.com Registered Users Posts: 13 Big grins
    edited June 1, 2010
    Okay I am getting
    [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.
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited June 1, 2010

    are you posting or putting to this url ?
    David Parry
    SmugMug API Developer
    My Photos
  • TerenceKearns.comTerenceKearns.com Registered Users Posts: 13 Big grins
    edited June 1, 2010
    devbobo wrote: »
    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...
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited June 1, 2010
    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
    David Parry
    SmugMug API Developer
    My Photos
  • TerenceKearns.comTerenceKearns.com Registered Users Posts: 13 Big grins
    edited June 3, 2010
    devbobo wrote: »
    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.comTerenceKearns.com Registered Users Posts: 13 Big grins
    edited June 7, 2010
    The "Entity too large" thing is a separate issue so I am going to move it to a new thread.
Sign In or Register to comment.