Starting to play with APIs
pearsonartphoto
Registered Users Posts: 34 Big grins
Hey all,
I'm starting to try and play with APIs, for the first time ever as a matter of fact. I've done alot of stand-alone computing before, but I decided it's time to join the 21st century finally. Of the easily web-enabled languages, my strongest suit is Python, and looking at the Json format seems to be the easiest thing. My first project is going to involve Smugmug, but I'm having problems even doing the simplest things. Specifically, I'm trying to do an anonymous login, but I seem to be missing something really obvious... Essentially my 3-line piece of code looks like this:
kwargs={"APIKey": ["MY_PUBLIC_API_KEY_HERE"],"MethodName":["smugmug.login.anonymously"]}
url="http://api.smugmug.com/hack/json/1.2.0/"+urllib.parse.urlencode(kwargs);
results=json.load(urllib.request.urlopen(url))
For those not as well versed in python, essentially what this does is create a URL string as listed below, and sends a request to that URL. Then the build in json library will decode it.
'http://api.smugmug.com/hack/json/1.2.0/APIKey=[%MY_PUBLIC_API_KEY_HERE']&MethodName=['smugmug.login.anonymously']'
I'm getting a 404 error, meaning the url is not listed. I've tried several other combinations, but I just keep getting the feeling that I'm missing something painfully obvious... Is this what my URL string should be looking like? I should also mention that I used my real public API key, I'm still too new at this to know how open I should reveal the public API key, or for that matter if that's the one I should be using at all. I'm also noticing that they are requesting we send some kind of version information as well, should that just be tagged on to the end? Thanks so much!
I'm starting to try and play with APIs, for the first time ever as a matter of fact. I've done alot of stand-alone computing before, but I decided it's time to join the 21st century finally. Of the easily web-enabled languages, my strongest suit is Python, and looking at the Json format seems to be the easiest thing. My first project is going to involve Smugmug, but I'm having problems even doing the simplest things. Specifically, I'm trying to do an anonymous login, but I seem to be missing something really obvious... Essentially my 3-line piece of code looks like this:
kwargs={"APIKey": ["MY_PUBLIC_API_KEY_HERE"],"MethodName":["smugmug.login.anonymously"]}
url="http://api.smugmug.com/hack/json/1.2.0/"+urllib.parse.urlencode(kwargs);
results=json.load(urllib.request.urlopen(url))
For those not as well versed in python, essentially what this does is create a URL string as listed below, and sends a request to that URL. Then the build in json library will decode it.
'http://api.smugmug.com/hack/json/1.2.0/APIKey=[%MY_PUBLIC_API_KEY_HERE']&MethodName=['smugmug.login.anonymously']'
I'm getting a 404 error, meaning the url is not listed. I've tried several other combinations, but I just keep getting the feeling that I'm missing something painfully obvious... Is this what my URL string should be looking like? I should also mention that I used my real public API key, I'm still too new at this to know how open I should reveal the public API key, or for that matter if that's the one I should be using at all. I'm also noticing that they are requesting we send some kind of version information as well, should that just be tagged on to the end? Thanks so much!
0
Comments
Okay, so I found a super simple guide to using the API in python, actually a simple script. Exactly what I was looking for. Hopefully I'll be able to make some progress now;-)
http://blog.fullvalence.com/2008/12/01/smugmug-uploader/
Okay, now that I've started to successfully hack my way around using the API (I've got a simple script to print every public album I own, and I'm working on a few other tools as well), I'm trying to find out more information about communities. I see there is a link in the 1.2.2 API to get the names of the communities, but is there a way to get the galleries in a given community?
I'm hoping to expand that functionality in version 1.2.3.
Cheers,
David
SmugMug API Developer
My Photos