Published in: PHP
<?php class Tumblr{ /* Tumblr API PHP class by Evan Walsh http://code.evanwalsh.net/Projects/Tumblr */ function read($url,$json = false){ $url = "$url/api/read"; if($json){ $url .= "/json"; } } $c = curl_init($url); curl_setopt($c,CURLOPT_HEADER,1); curl_setopt($c,CURLOPT_RETURNTRANSFER,1); $output = curl_exec($c); } else{ $output = "error: cannot fetch file"; } return $output; } function init($email,$password,$generator = "Tumblr PHP class"){ $this->email = $email; $this->password = $password; $this->generator = $generator; } function post($data){ $data["email"] = $this->email; $data["password"] = $this->password; $data["generator"] = $this->generator; $request = http_build_query($data); $c = curl_init('http://www.tumblr.com/api/write'); curl_setopt($c,CURLOPT_POST,true); curl_setopt($c,CURLOPT_POSTFIELDS,$request); curl_setopt($c,CURLOPT_RETURNTRANSFER,true); $return = curl_exec($c); $status = curl_getinfo($c,CURLINFO_HTTP_CODE); curl_close($c); if($status == "201"){ return true; } elseif($status == "403"){ return false; } else{ return "error: $return"; } } else{ return "error: cURL not installed"; } } function check($action){ $data["email"] = $this->email; $data["password"] = $this->password; $data["generator"] = $this->generator; $data["action"] = $action; $c = curl_init('http://www.tumblr.com/api/write'); curl_setopt($c,CURLOPT_POST,true); curl_setopt($c,CURLOPT_POSTFIELDS,$data); curl_setopt($c,CURLOPT_RETURNTRANSFER,true); $result = curl_exec($c); $status = curl_getinfo($c,CURLINFO_HTTP_CODE); curl_close($c); if($status == "200"){ $status = true; } elseif($status == "403" || $status == "400"){ $status = false; } return $status; } else{ return "error: cURL not installed"; } } } } ?>
Comments
Subscribe to comments
You need to login to post a comment.

Hey, thanks for posting this! :]