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!

Labels: , ,

Posted by Vivek at 5:42 PM | 4 comments | links to this post read on

Ubuntu over Windows XP!!

Installing linux on your machinge can be a difficult decision for most wanna-feel-like-geeks, especially when the laptop in question is owned not by them, but by their employer, and has elaborate encryption technologies in place at the BIOS level to prevent loss of information in case the laptop is lost. Yes, I'm not talking of a general dilemma, but of my predicament.

Enter Microsoft Virtual PC. This sounded interesting. So much so that I initially tried installing the latest releases of Fedora and Ubuntu on it, without much luck. There weren't many articles on how to do this either. All the help I got was either for Ubuntu 6.06 or Fedora 5. So after a while I gave up.

Yesterday I decided to lower my expectations and install the older version of Ubuntu Linux. It was a rather easy install, and most of my hardware worked like a dream. I had to manually install the soundcard, but the network and display were working fine anyway.

I can't wait for someone to hack Leopard enough so that I can go ahead and install that too.. That will surely be fun. But till then, take a look at these lovely screenshots. This blog post is being written inside Ubuntu by the way, but I will eventually have to add the windows screen shot from windows itself, because I still haven't figured out the host system access from within the virtual machine.

Next stop, VMWare.

AHA!! The advantage of having 2 machines is that I could save on the non host and use the "Windows Share" connection from Ubuntu to access the screenshot. This thing is a dream. I remember the first time I tried to use Samba on Mandrake, I almost wanted to kill myself!


From within Ubuntu



From Windows XP

So, entirely from within Ubuntu. My very first post :) And may I add, that I even saw a bit of Cheeni Kum on Ubuntu Today.. Funny things can bring excitement back in life!

Labels:

Posted by Vivek at 12:39 PM | 1 comments | links to this post read on

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&amp;calltime=1192904962&amp;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: , , , ,

Posted by Vivek at 11:35 PM | 1 comments | links to this post read on

My Photo
Name: Vivek Kapoor
Location: Delhi, India

I'm just another face in the crowd. I have the same dreams as every other engineer in the country, the same lifestyle, the same aspirations. Yet, we all feel we are so different. Maybe we are, but we do little to prove it. We do little to live by our convictions, to share our thoughts. I'm trying to do a million things at once. Thinking about my future is more a habit than a hobby, and running an e-commerce website my present biggest obsession. Yet, on paper, I'm just another software professional like so many others.. doing a 11-5 (yeah, lovely timings) job. This blog is testimony to the fact that I may not get very far, like millions of others, but still, I'm different, and hopefully, I'll get around to proving myself.