How do get Smugmug API & SessionId

test.iwavetest.iwave Registered Users Posts: 3 Beginner grinner
I am web site developer. I am using " Smugmug API ". I created API key "
xxxx ".
I am using that URL "
http://api.smugmug.com/services/api/json/1.2.2/?method=smugmug.albums.get&SessionID=xxxxx"
. I got the following error message "
{"stat":"fail","method":"smugmug.albums.get","code":18,"message":"invalid
API key"} ".
How do i solve this problem. Please help me..

Comments

  • pearsonartphotopearsonartphoto Registered Users Posts: 34 Big grins
    edited August 27, 2010
    First of all, you probably don't want to publish your API key... You might consider deleting the key that you have and starting with a new one. Secondly, the flow is like this.

    1) Get a session ID- Use smugmug.login.anonymously if you want to browse publicly avaliable images, or use one of the other login methods provided in the documentation. See the docs for the arguments.
    2) Use the session ID that comes back from Smugmug there in every other command you send.

    If you do that, it should work fine. Good luck!
  • test.iwavetest.iwave Registered Users Posts: 3 Beginner grinner
    edited August 28, 2010
    Invalid user - Error
    Dear,

    Thanks you for you guidelines. I am using CURL function. I got the Invalid user error ( error code 4 ) . How do i solve that problem ?


    [PHP]

    $ch = curl_init() or die(curl_error());
    $chs = curl_init() or die(curl_error());
    curl_setopt($ch, CURLOPT_URL,"http://api.smugmug.com/services/api/json/1.2.2/?APIKey=xxxxx&JSONCallback=jsonSmugmugApi&method=smugmug.login.anonymously");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data1=curl_exec($ch) or die(curl_error());

    $str = preg_replace("/([a-zA-Z0-9_]+?):/" , "\"$1\":", $data1); // fix variable names
    $output = json_decode($str, true);
    echo "<pre>";
    var_dump($output);
    echo "</pre>";
    $sessionid = $output;

    curl_setopt($chs, CURLOPT_URL,"http://api.smugmug.com/hack/json/1.2.0/?method=smugmug.albums.get&SessionID=".$sessionid."&SitePassword=observer1");
    curl_setopt($chs, CURLOPT_RETURNTRANSFER, 1);
    $result_details =curl_exec($chs) or die(curl_error());
    echo "<font color=black face=verdana size=3>".$result_details."</font>";
    echo curl_error($chs);
    curl_close($chs);
    echo curl_error($ch);
    curl_close($ch)


    [/PHP]rolleyes1.gif
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited August 28, 2010
    If you are logging in anonymously, there you have no user context, so if you call methods like smugmug.albums.get, you need to provide the NickName parameter.
    David Parry
    SmugMug API Developer
    My Photos
Sign In or Register to comment.