I am trying to set up an automatic tumblr post every time I add something new to my site. I am using the following code:
$conskey = "APIKEY"; $conssec = "APISECRET"; $tumblr_blog = "blogname.tumblr.com"; $to_be_posted = "This is the text to be posted"; $oauth = new OAuth($conskey,$conssec); $oauth->fetch("http://api.tumblr.com/v2/blog/".$tumblr_blog."/post", array('type'=>'text', 'body'=>$to_be_posted), OAUTH_HTTP_METHOD_POST); $result = json_decode($oauth->getLastResponse()); if($result->meta->status == 200){ echo 'Success!'; }
As far as I can tell, everything is formatted correctly. However, this is the first time I have tried to connect to the JSON API using Oauth, so I am not completely sure what I am doing.
This is the exact error I get:
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in /home/public_html/edge/tumblr.php:35 Stack trace: #0 /home/public_html/edge/tumblr.php(35): OAuth->fetch('http://api.tumb...', Array, 'POST') #1 /home/public_html/edge/index.php(95): include('/home/...') #2 {main} thrown in /home/public_html/edge/tumblr.php on line 35
Line 35 is the line starting with $ oauth-> fetch.
Thanks for any help :-)
EDIT I solved the problem by replacing my previous code with this page
source share