Mental Masturbation, Musings, and Methods

The Mind of Alex Beutel

PHP and Acrobat.com

June 5th, 2008 · 2 Comments

A good while ago I heard about Adobe acquiring Buzzword, which was quite exciting since it definitely seemed like the most clean of the up and coming online document editing software.  Finally, just last week Adobe released a public beta of a suite of Buzzword, Share, and other online editing tools to go along with their release of Adobe Acrobat 9.  So, of course, I signed up, played around a bit before going to work in the morning and took a quick peek at the Share API.  Well to jump to the point,  I am excited at the possibilities but disappointed in Adobe.  For a company that is usually solid in their product releases, this is very beta.  As I read in another blog post, there is no continuity to the suite.  As a matter of fact, why is it even a suite?  The multiple features available at Acrobat.com should be implemented together.  And, rather than worrying so much about their value, open the features up more.  5 PDFs per month?  Really?  Anybody that can use Google can find infinite other ways to convert their documents to PDF.  My final complaint is that the flash viewer used to share the documents is atrocious.  It is impossible to actually read any documents with it.  Adobe has beautiful flash paper and again by trying to retain value will just kill itself off in the face of newer compartively open formats like Scribd’s iPaper (just a hack of Flashpaper but at least more accessible conversion).

Anyway, regardless of the poor GUI congruity, I would like to discuss the API.  The site has a few public libraries at first appearance, and I must hand it to Adobe that their Java library looks extremely clean and easy to use.  But the Python library – not even a library, although probably the easiest reading of all of their online documentation.  The writer of the blog even states that he has given up and decided to use the Java library –  encouraging.  Anyway, disappointed in not even an attempt at a PHP implementation, I decided to give it a shot.  I essentially went as far as the writer of the Python blog post: authenticate, get sessionid, and get a list of files you have on your account.  (Note this requires PEAR’s HTTP_Request package.) Also, I know this is very ugly code and I’m possitive could and should be done much cleaner.  However, it works if your just trying to take the first steps and get some output.  If anyone wants to clean it up or continue on with a PHP implementation, feel free and let me know how it goes.  However, until they open up the platform to worthwhile features, it is sadly not worth my time.  Hopefully Adobe soon realizes the mistake of being so possessive and thinks a little more creatively about how to monetize their technology.  Anyway, here is the code; enjoy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
< ?php
$acrobat_api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$acrobat_shared_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$acrobat_base_url = "https://api.share.acrobat.com/webservices/api/v1/";
$acrobat_username = "your_username@somecompany.com";
$acrobat_password = "your_acrobat.com_password";
 
function getAuthToken()
{
	global $acrobat_api_key, $acrobat_shared_secret, $acrobat_base_url, $acrobat_password, $acrobat_username;
	$a = new HTTP_Request();
	$a->setURL($acrobat_base_url."auth/");
	$a->setMethod("POST");
	$time = time();
	$data = "POST https://api.share.acrobat.com/webservices/api/v1/auth/ ".$time;
	$md5 = md5($data.$acrobat_shared_secret);
	$auth = "AdobeAuth apikey=\"".$acrobat_api_key."\",data=\"".$data."\",sig=\"".$md5."\"";
	$request_body = "<request>\n<username>".$acrobat_username."</username>\n<password>".$acrobat_password."</password>\n</request>";
	$a->addHeader("Authorization", $auth);
	$a->setBody($request_body);
	$a->sendRequest();
	$xml = $a->getResponseBody();
	$regex = "<authtoken>[a-zA-Z0-9]+</authtoken>";
	$i = ereg($regex, $xml, $matches);
	$p = xml_parser_create();
	$i = xml_parse_into_struct($p, $matches[0], $vals, $index);
	$j = xml_parser_free($p);
	return $vals[0]['value'];
}
function getSession($auth_token)
{
	global $acrobat_api_key, $acrobat_shared_secret, $acrobat_base_url;
	$a = new HTTP_Request();
	$a->setURL($acrobat_base_url."sessions/");
	$a->setMethod("POST");
	$time = time();
	$data = "POST https://api.share.acrobat.com/webservices/api/v1/sessions/ ".$time;
	$md5 = md5($data.$acrobat_shared_secret);
	$auth = "AdobeAuth apikey=\"".$acrobat_api_key."\",data=\"".$data."\",sig=\"".$md5."\"";
	$request_body = "<request>\n<authtoken>".$auth_token."</authtoken>\n</request>";
	$a->addHeader("Authorization", $auth);
	$a->setBody($request_body);
	$a->sendRequest();
	$xml = $a->getResponseBody();
 
	$regex = "<sessionid>[a-zA-Z0-9]+</sessionid>";
	$i = ereg($regex, $xml, $matches);
	$p = xml_parser_create();
	$i = xml_parse_into_struct($p, $matches[0], $vals, $index);
	$j = xml_parser_free($p);
 
	$regex = "<secret>[a-zA-Z0-9]+</secret>";
	$i = ereg($regex, $xml, $matches2);
	$p = xml_parser_create();
	$i = xml_parse_into_struct($p, $matches2[0], $vals2, $index);
	$j = xml_parser_free($p);
 
	$response[0] = $vals[0]['value'];
	$response[1] = $vals2[0]['value'];
 
	return  $response;
}
function getList($session, $secret)
{
	global $acrobat_api_key, $acrobat_shared_secret, $acrobat_base_url;
	$a = new HTTP_Request();
	$a->setMethod("GET");
	$time = time();
	$data = "GET /webservices/api/v1/dc/ apikey=".$acrobat_api_key." calltime=".$time." sessionid=".$session;
	$md5 = md5($data.$secret);
	$url = $acrobat_base_url."dc/?apikey=".$acrobat_api_key."&calltime=".$time."&sessionid=".$session."&sig=".$md5;
	$a->setURL($url);
	$a->sendRequest();
	$xml = $a->getResponseBody();
	return $xml;
}
$auth = getAuthToken();
$response = getSession($auth);
$session = $response[0];
$secret = $response[1];
echo getList($session, $secret);
?>

Tags: PHP · Programming · Web Development

2 responses so far ↓

  • 1 professional teeth whitening // Sep 25, 2014 at 4:15 pm

    We are a gaggle of volunteers and opening a
    new scheme in our community. Your website provided
    us with useful information to work on. You’ve performed a formidable process and our entire neighborhood will likely be grateful to you.

  • 2 Merry // Oct 10, 2014 at 12:57 am

    An outstanding share! I’ve just forwarded this onto a friend who was doing
    a little research on this. And he in fact bought me lunch due to the
    fact that I stumbled upon it for him… lol. So let me reword this….
    Thanks for the meal!! But yeah, thanx for spending some
    time to discuss this subject here on your web site.

Leave a Comment