Options

Invalid APIkey on GetAlbums

mwilliamsmwilliams Registered Users Posts: 10 Big grins
Hi All,

I'm not sure what I'm doing wrong. I use the APIKey to login. I then do a request in the same fashion to smugmug.albums.get and it tells me the APIKey is invalid.

I'm using coldfusion cfhttp to post to http://api.smugmug.com/hack/rest/ which works perfectly when I login.

Page can be seen here:
http://somethingJava.com/omar/login.cfm

The API for smugmug doesn't even say that I need the APIKey for smugmug.albums.get. It just says i need the sessionID but regardless I put it in when I got the error and it did not resolve the error.

I need some help.

Thanks,
Marco

Comments

  • Options
    mwilliamsmwilliams Registered Users Posts: 10 Big grins
    edited August 19, 2005
    Got it to work!!! --- NOT!
    Well, It is wierd but I got it to work for 1 day. Then I came back the next day and I was getting the same error that I had before.

    Maybe someone can tell me what I am doing wrong. The code below is coldfusion. But it's pretty simple to understand. I really hope someone can help me on this. I'm doing a project for my wedding photographer and my wife needs our pictures up Pronto on his new website *smiles*
    Any help or input will be appreciated.

    Thanks,
    Marco

    PLEASE NOTE THAT THIS IS COLDFUSION CODE NOT PHP.
    I'm sorry about the color coding it was the only way I could get this interface to show my code.


    Start of the function
    [PHP]<cffunction name="getAlbums" access="public" returntype="struct" hint="Get smugmug Albums">[/PHP] <CFFUNCTION hint="Get smugmug Albums" returntype="struct" access="public" name="getAlbums">
    requited arguments that need to be passed to the function
    [PHP]<cfargument name="nickname" type="string" required="true">[/PHP]
    <CFARGUMENT name="nickname" required="true" type="string">
    Creates a coldfusion structure dataType
    [PHP] <cfset results = structNew()>[/PHP] <CFSET results="structNew()">
    If there is a session then login set the state to active and store in the structure otherwise login as an anonymous user.
    [PHP]<cfif isdefined("session.SessionID")>
    <cfset results.loginStatus = "Active">
    <cfelse>
    <cfset loginResults = login("anonymous")>
    <cfset results.loginStatus = "Timeout">
    </cfif>
    [/PHP]
    This code is what posts to the url at smugmug.
    [PHP]<cftry>
    <cfhttp method="post" url="http://api.smugmug.com/hack/rest/"&gt;
    <cfhttpparam type="formfield" name="method" value="smugmug.albums.get">
    [/PHP]
    I commented this out because it wouldn't take the SessionID when I got it to work that 1 day.
    [PHP]
    <!--- <cfhttpparam type="formfield" name="SessionID" value="#session.SessionID#"> --->




    <cfhttpparam type="formfield" name="Nickname" value="#arguments.nickname#">
    <cfhttpparam type="formfield" name="APIKey" value="#Application.APIKey#">
    </cfhttp> <CFHTTPPARAM name="method" type="formfield" value="smugmug.albums.get">
    The rest of this code is for the output only
    (cfhttp.FileContent is the variable that the above tag stores the returned xml document)
    This just parses the response
    [PHP]<cfset xmlParsed = XmlParse( cfhttp.FileContent ) >[/PHP]
    Catching any real bad errors thown, like smugmugs site being down.

    [PHP]
    <cfcatch type="any">
    <cfset xmlParsed.rsp.XmlAttributes.stat = "fail">
    <cfset xmlParsed.rsp.err.XmlAttributes.msg = "Invalid SmugMug Url or SmugMug Could not be contacted.">
    </cfcatch>
    </cftry>[/PHP] <CFCATCH type="any">
    <CFSET xmlParsed.rsp.XmlAttributes.stat="fail">
    <CFSET xmlParsed.rsp.err.XmlAttributes.msg="Invalid SmugMug Url or SmugMug Could not be contacted.">
    </CFCATCH>
    </CFTRY>

    Stores the Parsed XML into a coldfusion structure.
    [PHP]<cfset results.xmlParsed = xmlParsed>[/PHP]
    <CFSET results.xmlParsed="xmlParsed">
    Returns the structure
    [PHP]<cfreturn results>
    </cffunction>[/PHP] <CFRETURN results>
    </CFFUNCTION>
  • Options
    devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited August 22, 2005
    Marco,

    Just been looking through your code, I haven't used the REST interface...but i have used the XMLRPC interface extensively.

    I tried your code (on that web site) seems to log in ok but I get an "Invalid User" message when I try to get the albums.

    Based on this, looking through your code I make 2 observations. Firstly, I am pretty sure parameters are case-sensitive. NickName should be in this case, but it's not like that in your code.

    Secondly, this parameter is optional...it doesn't need to be used if you are logging on with a username and password if you only want to access ur own galleries. However, if you log on anonmyously or log on with a username and password...and want to access galleries from a different user.

    Hope this helps,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • Options
    onethumbonethumb Administrators Posts: 1,269 Major grins
    edited August 26, 2005
    devbobo wrote:
    Marco,

    Just been looking through your code, I haven't used the REST interface...but i have used the XMLRPC interface extensively.

    I tried your code (on that web site) seems to log in ok but I get an "Invalid User" message when I try to get the albums.

    Based on this, looking through your code I make 2 observations. Firstly, I am pretty sure parameters are case-sensitive. NickName should be in this case, but it's not like that in your code.

    Secondly, this parameter is optional...it doesn't need to be used if you are logging on with a username and password if you only want to access ur own galleries. However, if you log on anonmyously or log on with a username and password...and want to access galleries from a different user.

    Hope this helps,

    David

    Two great points. Yes, 'NickName' is case sensitive - 'nickname' will fail. Same for all other parameters you'll be passing.

    And 'NickName' is only necessary if you're A) logged in anonymously, or B) getting someone else's albums.

    Given how easy it is to debug REST calls (simply build the URL and paste it into your web browser to see what happens), can you give us your full albums.get URL you're trying to use, so we can take a look ourselves?

    Thanks,

    Don
  • Options
    mwilliamsmwilliams Registered Users Posts: 10 Big grins
    edited August 30, 2005
    Rest Url
    I'm actually using form posts. So it's not posting as a "GET" method. But I would imagine that it would look something like this.

    http://api.smugmug.com/hack/rest/?Method=smugmug.albums.get&NickName=lesliescreations&APIKey=XXXXXXXX


    But this brings me to a point I should have thought about a while ago, that I could try this url and if it works then there is something wrong I'm doing.

    I'm going to try it out and see. In the meantime, I've noticed some wierd things happening, like my code working one day and then the next it doesn't without any changes.

    [New: Update]
    I am editing this post because I have some new information. I put together a url that should work and I still get the Invalid APIKey msg. If I go to this URL why do I get an Invalid APIKey Error when I am not even required to pass the APIKey only a SessionID?

    http://api.smugmug.com/hack/rest/?method=smugmug.images.get&SessionID=OMAR_2031991_50890039&AlbumID=32486

    If the session is invalid when you try this link then login anonymously at:
    http://somethingJava.com/omar/login.cfm
    Then Click on getSession Link. It will give you a SessionID to use.

    Any more input on my code would be appreciated. I will make sure I'm using case sensitive variables. But I think it might be something else.

    Thanks,
    Marco
  • Options
    mwilliamsmwilliams Registered Users Posts: 10 Big grins
    edited September 1, 2005
    Finally Resolution.
    So I fixed it! I wanted to share my findings so here they are.

    What I was doing wrong, and you coldfusion lovers are going to get a kick out of this, is that CF creates sessionID's by default when you have and Applicaiton.cfm file and you set the applicaiton to accept sessions via
    cfapplication name="omar" sessionmanagement="yes" sessiontimeout="30"

    So i was using the var "SessionID" and it was giving me the coldfusion session instead of my creating a unique name like "sid" and storing the smugmug session. Then I was sending the coldfusion session to smugmug and it was flippin me the APIKey error. Once I changed my variable name and passed the smugmug session to smugmug it worked perfectly.

    Hope that made sence to someone.

    Thanks everyone for their help.

    Marco
Sign In or Register to comment.