tag:blogger.com,1999:blog-29462451.post-20136285946720406932007-10-30T17:42:00.001+05:302007-10-30T17:49:41.045+05:30Connecting to Adobe Share using Python V2In 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.<br /><br />1. Get the AuthToken<br /><span style="font-family:courier new;"></span><blockquote><span style="font-family:courier new;">import time, md5, httplib2, xml.dom.minidom, sys</span><br /><span style="font-family:courier new;">shared = "085960468662212c21417dce2e1XXXXX"</span><br /><span style="font-family:courier new;">calltime = str(int(time.time()))</span><br /><span style="font-family:courier new;">datastring = "POST /webservices/api/v1/auth/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=" + calltime</span><br /><span style="font-family:courier new;">sig = (md5.new(datastring+shared).hexdigest())</span><br /><span style="font-family:courier new;">url = "https://api.share.adobe.com/webservices/api/v1/auth/?apikey=fdc464509d733be99c30c6ccfacXXXXX&amp;calltime="+calltime +"&amp;sig=" + sig</span><br /><span style="font-family:courier new;">bodydata = '&lt;request&gt;&lt;username&gt;vkapoor@adobe.com&lt;/username&gt;&lt;password&gt;XXXXX&lt;/password&gt;&lt;/request&gt;'</span><br /><span style="font-family:courier new;">http = httplib2.Http()</span><br /><span style="font-family:courier new;">response, content = http.request(url , method='POST', body=bodydata)</span><br /><span style="font-family:courier new;">Doc = xml.dom.minidom.parseString(content)</span><br /><span style="font-family:courier new;">L = Doc.getElementsByTagName("authtoken")</span><br /><span style="font-family:courier new;">authToken = str((L[0].childNodes)[0].data)</span></blockquote><span style="font-family:courier new;"></span><br /><br />2. At the end of this, <span style="font-family:Courier New;">authToken <span style="font-family:georgia;">should have the Authorization Token. Now use this to start a new session</span>.<br /><br /><blockquote>calltime = str(int(time.time()))<br />datastring = "POST /webservices/api/v1/sessions/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=" + calltime<br />sig = (md5.new(datastring+shared).hexdigest())<br />url = "https://api.share.adobe.com/webservices/api/v1/sessions/?apikey=fdc464509d733be99c30c6ccfacXXXXX&amp;calltime="+calltime +"&amp;sig=" + sig<br />bodydata = '&lt;request&gt;&lt;authtoken&gt;'+ authToken + '&lt;/authtoken&gt;&lt;/request&gt;'<br />response, content = http.request(url , method='POST', body=bodydata)<br />Doc = xml.dom.minidom.parseString(content)<br />L = Doc.getElementsByTagName("sessionid")<br />sessionid = str((L[0].childNodes)[0].data)<br />L = Doc.getElementsByTagName("secret")<br />secret = str((L[0].childNodes)[0].data)<br />L = Doc.getElementsByTagName("name")<br />name = str((L[0].childNodes)[0].data)<br />L = Doc.getElementsByTagName("level")<br />level = str((L[0].childNodes)[0].data)</blockquote><br /><span style="font-family:georgia;">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 </span><span style="font-family:Courier New;"><span style="font-family:georgia;">sessionid, secret, name, level etc. Other information can be extracted conveniently using XML methods.</span><br /><span style="font-family:georgia;">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..</span><br /><br /><blockquote>calltime = str(int(time.time()))<br />datastring = "GET /webservices/api/v1/dc/ apikey=fdc464509d733be99c30c6ccfacXXXXX calltime=" + calltime + " sessionid=" + sessionid<br />sig = (md5.new(datastring+secret).hexdigest())<br />url = "https://api.share.adobe.com/webservices/api/v1/dc/?apikey=fdc464509d733be99c30c6ccfacXXXXX&amp;calltime="+calltime +"&amp;sessionid=" + sessionid + "&amp;sig=" + sig<br />response, content = http.request(url , method='GET')</blockquote><br /><br /><span style="font-family:georgia;">4.Parse the variable </span><span style="font-family:Courier New;"><span style="font-family:georgia;">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.</span><br /><br /><span style="font-family:georgia;">Notice that we recalculate the </span><span style="font-family:Courier New;"><span style="font-family:georgia;">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.</span><br /><br /><span style="font-family:georgia;">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.</span><br /><br /><span style="font-family:georgia;">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!</span><br /></span></span></span></span><div class="blogger-post-footer">Helloi</div>Vivekhttp://www.blogger.com/profile/09990763077941665358noreply@blogger.com