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!
About this entry
You’re currently reading “
- Published:
- 5:42 PM
- by Vivek



1 Comments (Post a Comment)