Alex Beutel's Blog

PHP and Acrobat.com

June 5th, 2008 · No Comments

 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 = "\n".$acrobat_username."\n".$acrobat_password."\n";$a->addHeader("Authorization", $auth);$a->setBody($request_body);$a->sendRequest(); $xml =$a->getResponseBody(); $regex = "[a-zA-Z0-9]+";$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 = "\n".$auth_token."\n"; $a->addHeader("Authorization",$auth); $a->setBody($request_body); $a->sendRequest();$xml = $a->getResponseBody();$regex = "[a-zA-Z0-9]+"; $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 = "[a-zA-Z0-9]+";$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); ?>