我正在尝试通过Cron每天自动发布消息到我的Tumblr博客。
我在这里使用官方的Tumblr PHP库: https://github.com/tumblr/tumblr.php 并且使用这里详细介绍的身份验证方法: https://github.com/tumblr/tumblr.php/wiki/Authentication (或其中的部分,因为我不需要用户输入!)
我有以下代码。
然而,这给我带来了以下错误:
致命错误:未捕获的Tumblr\API\RequestException:[401]:未经授权抛出 /home///*/vendor/tumblr/tumblr/lib/Tumblr/API/Client.php 第426行
我可以正常检索博客文章和其他数据(例如):
所以看起来只是在发布一个我无法管理的帖子。
老实说,我真的不太理解OAuth身份验证,所以我正在使用一些更有价值的程序员们慷慨提供的免费代码 :-) 我假设我可以编辑掉https://github.com/tumblr/tumblr.php/wiki/Authentication的部分,因为我不需要用户输入,这只是直接从我的服务器上运行的代码(通过Cron)。
我花了几天的时间在互联网上寻找答案(有一点进展),但在这个问题上完全陷入困境...
非常感谢任何建议!
我在这里使用官方的Tumblr PHP库: https://github.com/tumblr/tumblr.php 并且使用这里详细介绍的身份验证方法: https://github.com/tumblr/tumblr.php/wiki/Authentication (或其中的部分,因为我不需要用户输入!)
我有以下代码。
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);
然而,这给我带来了以下错误:
致命错误:未捕获的Tumblr\API\RequestException:[401]:未经授权抛出 /home///*/vendor/tumblr/tumblr/lib/Tumblr/API/Client.php 第426行
我可以正常检索博客文章和其他数据(例如):
echo '<pre>';
print_r( $client->getBlogPosts($blogName, $options = null) );
echo '</pre>';
所以看起来只是在发布一个我无法管理的帖子。
老实说,我真的不太理解OAuth身份验证,所以我正在使用一些更有价值的程序员们慷慨提供的免费代码 :-) 我假设我可以编辑掉https://github.com/tumblr/tumblr.php/wiki/Authentication的部分,因为我不需要用户输入,这只是直接从我的服务器上运行的代码(通过Cron)。
我花了几天的时间在互联网上寻找答案(有一点进展),但在这个问题上完全陷入困境...
非常感谢任何建议!
第426行
或者你的代码中哪一行调用了那一行吗? - Nathan F.