我曾经费尽心思搜索,但是无法找到相关答案。 我想知道是否有人遇到过Tumblr API v2调用,可以让您访问私有博客的数据。 当然,我想要在提供身份验证的情况下发布和检索列表来自我的一些私人博客。
谢谢
通过正确的OAuth调用API,并使用私人博客的访问令牌,可以使用Tumblr API v2访问至少一些私人博客的信息。
以下是我的一些观察:
api.tumblr.com/v2/blog/{base-hostname}/posts
Normally you make this call with your Public API Key, and that allows you to access the posts of any Tumblr that is not private.
However! Good news: If you include the full OAuth headers when making this request, it will return the list of posts of a Private Tumblr account. You need an access Token for that Tumblr, of course, to do this. Yes, I have tried this, done this, and it works.
If you only use your consumer API key, e.g.
api.tumblr.com/v2/blog/{base-hostname}/posts?api_key=w8878374r384r...
Then you will get nothing. You have to make a fully-authenticated request with all of the proper OAuth parameters.
api.tumblr.com/v2/blog/{base-hostname}/info
Will not work at all for a private blog, even when using all the proper OAuth stuff to make the API call.
api.tumblr.com/v2/user/info
Normally this returns a list of "blogs" for the given authenticated user. However, any private tumblrs will not show up in this list of blogs.
注意:
我还没有测试许多私有博客的其他API调用,所以我不能确定创建/编辑/删除文章是否有效。
我尚未使用xAuth进行测试,只使用过常规OAuth和通过“Web授权流程”获得的标准访问令牌。
$conskey = "CONSUMER KEY";
$conssec = "CONSUMER SECRET";
$tumblr_blog = "myblog.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!';
}
尝试使用API上面的代码来发布博客。
希望能有所帮助。
oAuth类
? $oauth = new OAuth($conskey,$conssec);
- t q