I am trying to post messages automatically to my Tumblr Blog (which will run daily via Cron)
I am using the Official Tumblr PHP library here: https://github.com/tumblr/tumblr.php
And using the Authentication method detailed here : https://github.com/tumblr/tumblr.php/wi ... entication (or parts of this, as I don't need user input!)
I have the below code
Код: Выделить всё
require_once('vendor/autoload.php'); // some variables that will be pretttty useful $consumerKey = 'MY-CONSUMER-KEY'; $consumerSecret = 'MY-CONSUMER-SECRET'; $client = new Tumblr\API\Client($consumerKey, $consumerSecret); $requestHandler = $client->getRequestHandler(); $blogName = 'MY-BLOG-NAME'; $requestHandler->setBaseUrl('https://www.tumblr.com/'); // start the old gal up $resp = $requestHandler->request('POST', 'oauth/request_token', array()); // get the oauth_token $out = $result = $resp->body; $data = array(); parse_str($out, $data); // set the token $client->setToken($data['oauth_token'], $data['oauth_token_secret']); // change the baseURL so that we can use the desired Methods $client->getRequestHandler()->setBaseUrl('http://api.tumblr.com'); // build the $postData into an array $postData = array('title' => 'test title', 'body' => 'test body'); // call the creatPost function to post the $postData $client->createPost($blogName, $postData);
Fatal error: Uncaught Tumblr\API\RequestException: [401]: Not Authorized thrown in /home///*/vendor/tumblr/tumblr/lib/Tumblr/API/Client.php on line 426
I can retrieve blog posts and other data fine with (example):
Код: Выделить всё
echo ''; print_r( $client->getBlogPosts($blogName, $options = null) ); echo '';
In all honesty, I don't really understand the OAuth Authentication, so am using code that more worthy coders have kindly provided free

I have spent days looking around the internet for some answers (have gotten a little further), but am totally stuck on this one...
Any advice is much appreciated!
Источник: https://stackoverflow.com/questions/213 ... tumblr-api