Json Tumblr Oauth在API v2上返回401

Json Tumblr Oauth在API v2上返回401,json,api,oauth,tumblr,Json,Api,Oauth,Tumblr,每次我在网站上添加新内容时,我都会尝试设置一个自动的tumblr帖子。我正在使用以下代码: $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.tu

每次我在网站上添加新内容时,我都会尝试设置一个自动的tumblr帖子。我正在使用以下代码:

$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!';
}
据我所知,这些都是格式正确的。然而,这是我第一次尝试使用Oauth连接到JSON API,所以我对我正在做的事情并不完全有信心

这正是我收到的错误:

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
第35行是以$oauth->fetch开头的行

谢谢您的帮助:-)

编辑 我用上的示例替换了以前的代码,从而解决了这个问题