Connecting to Adobe Share using Python V2
In the previous post about Python and Adobe Share, I explained the very basic step of communicating with the Share server and obtaining a Authorization token. The next step is to use this authorization token to start a session with the Share server. Lets start with the basics again, no explanations this time.1. Get the AuthToken
import time, md5, httplib2, xml.dom.minidom, sys
shared = "085960468662212c21417dce2e1XXXXX"
calltime = str(int(time.time()))
datastring = "POST /webservices/api/v1/auth/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=" + calltime
sig = (md5.new(datastring+shared).hexdigest())
url = "https://api.share.adobe.com/webservices/api/v1/auth/?apikey=fdc464509d733be99c30c6ccfacXXXXX&calltime="+calltime +"&sig=" + sig
bodydata = '<request><username>vkapoor@adobe.com</username><password>XXXXX</password></request>'
http = httplib2.Http()
response, content = http.request(url , method='POST', body=bodydata)
Doc = xml.dom.minidom.parseString(content)
L = Doc.getElementsByTagName("authtoken")
authToken = str((L[0].childNodes)[0].data)
2. At the end of this, authToken should have the Authorization Token. Now use this to start a new session.
calltime = str(int(time.time()))
datastring = "POST /webservices/api/v1/sessions/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=" + calltime
sig = (md5.new(datastring+shared).hexdigest())
url = "https://api.share.adobe.com/webservices/api/v1/sessions/?apikey=fdc464509d733be99c30c6ccfacXXXXX&calltime="+calltime +"&sig=" + sig
bodydata = '<request><authtoken>'+ authToken + '</authtoken></request>'
response, content = http.request(url , method='POST', body=bodydata)
Doc = xml.dom.minidom.parseString(content)
L = Doc.getElementsByTagName("sessionid")
sessionid = str((L[0].childNodes)[0].data)
L = Doc.getElementsByTagName("secret")
secret = str((L[0].childNodes)[0].data)
L = Doc.getElementsByTagName("name")
name = str((L[0].childNodes)[0].data)
L = Doc.getElementsByTagName("level")
level = str((L[0].childNodes)[0].data)
3. At the end of this, some relevant data, such as the SessionID, the new shared secret and other information is available in variables such as sessionid, secret, name, level etc. Other information can be extracted conveniently using XML methods.
Now, let us do something productive. Starting a session has no meaning if you can't do anything. So, just to prove that you can, I'll write a snippet that will list the contents of the root directory. Here goes..
calltime = str(int(time.time()))
datastring = "GET /webservices/api/v1/dc/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=" + calltime + " sessionid=" + sessionid
sig = (md5.new(datastring+secret).hexdigest())
url = "https://api.share.adobe.com/webservices/api/v1/dc/?apikey=fdc464509d733be99c30c6ccfacXXXXX&calltime="+calltime +"&sessionid=" + sessionid + "&sig=" + sig
response, content = http.request(url , method='GET')
4.Parse the variable content in order to get relevant information. If all goes well, it should have a list of files, or rather a tree of files in the root of your Share account.
Notice that we recalculate the calltime before each new action. The Share server is ok as long as the calltimes are non decreasing. Also, in the last part, i.e. the directory listing, we use the new shared secret which is unique to a session.
This should get you started. I have used the Query String methods for all of these examples. I have reason to believe that if the Header methods are handled correctly, they should work too. I was not able to get the Header techniques to work, and I especially had doubts about the multipart upload techniques for uploading files. If anyone figures this out, I'd like to glance at the code.
I personally however gave up on using Python, and used the Java API provided by Adobe instead. That works like a dream to say the least, but I'd like to get this working too. Help!
Connecting to Adobe Share using Python
Adobe recently launched the Share Beta, a state of the art flash based file sharing and archiving solution. All of these services are headed in only one direction, the web. Also, there is an increasing desire to make connecting to these services easier. Adobe Share uses the RESTful paradigm to allow users to connect to the back end and communicate with the server, for automating tasks that would usually require user interaction.The Share forums currently provide links to API's for connecting to the service in Java and Action Script 3. I am not comfortable with either, and I wanted to use Python for this purpose, because it fits in well with my wider objective, and hence I can script everything in a single language. After hours of frantic searching, I wasn't able to find a decent tutorial on the RESTful methods in Python, leave alone Adobe Share specific help.
So after much hard work, I was able to get the responce I wanted, and after several ugly monsters like
'BadSig'
'BadAuthQuery'
and several others, I finally saw the light, and the server said:
'<response status="ok"><authtoken>2a5b93f2321a78172062219ab8ce3f25</authtoken></response>'</blockquote>
aah.. isn't that pretty.... You will surely understand if you have been trying as hard as I had to. So this is the end of one (no not all, its not panacea, just a lil blog, whatdayaexpect!) of your woes. This post will describe the very basics of getting a AuthToken using the Adobe Share API from Python.
So lets get started,
First things first, what all do you need over and above the standard Python installation? Only httplib2. (I use Python 2.5.1, and that seems to have everything else for this task anyway).
Import all you need, and create the data string and signature as described in the Share API documentation:
>>> import time, md5, httplib2
>>> shared = "085960468662212c21417dce2e1XXXXX"
>>> datastring = "POST /webservices/api/v1/auth/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=" + str(int(time.time()))
>>> datastring
'POST /webservices/api/v1/auth/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=1192904962'
>>> sig = (md5.new(datastring+shared).hexdigest())
>>> url = "https://api.share.adobe.com/webservices/api/v1/auth/?apikey=fdc464509d733be99c30c6ccfacXXXXX&calltime=1192904962&sig=" + sig
>>> bodydata = '<request><username>vkapoor@adobe.com<password>XXXXXXX</password>'
>>> http = httplib2.Http()
>>> response, content = http.request(url , method='POST', body=bodydata)
>>> response
{'date': 'Sat, 20 Oct 2007 18:33:18 GMT', 'status': '200', 'content-length': '88', 'content-type': 'application/xml;charset=ISO-8859-1', 'server': 'Apache-Coyote/1.1'}
>>> content
'<response status="ok"><authtoken>156e799bf4cac31eee170c2116cf5646</authtoken></response>'
So, there. Thats the first step for establishing a connection with the Adobe Share server, using Python and the RESTful approach. I will soon update on setting up a session, and uploading a PDF using Python. Stay tuned..
Labels: Adobe, Python, RESTful, Share, Web
Image Tagging Timepass
Don't feel like working? Never able to find graphics you are looking for in Google's image search? Purrfekt! Go right here to waste your time! Google seems to be getting a difficult image processing task done for free, with eager enthusiasts willing to waste time and energy in labeling images. Where is the need to develop cutting edge algorithms that identify objects within images and tag them, when you have millions of idle human brains at your disposal.The concept is novel to say the least. You are paired with a random unknown partner, and both of you are shown a common image. You are supposed to type out whatever occurs to you when you see the image, and if any of these words match, the image is tagged with that label. Pretty safe and effective. Try it for yourself, its fun.
I still don't know what I'm supposed to do with the points I've earned though.. Can I exchange them for lifesavers... anyone??
Labels: Web

