使用 php 发布到 tumblr
谁能帮我弄清楚如何使用 php 向 tumblr 发帖。 我尝试在谷歌上搜索库或示例代码,但找不到。我能找到的就是这里 https://github.com/alexdunae/ tumblr-php/blob/master/Tumblr.php ,它似乎也不起作用,我查看并尝试了 tumblr 网站上 v1 api 上的代码,也不起作用......
function post($data){
if(function_exists("curl_version")){
$data["email"] = $this->email;
$data["password"] = $this->password;
$data["generator"] = $this->generator;
$request = http_build_query($data);
$c = curl_init('http://www.tumblr.com/api/write');
curl_setopt($c,CURLOPT_POST,true);
curl_setopt($c,CURLOPT_POSTFIELDS,$request);
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
$return = curl_exec($c);
$status = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if($status == "201"){
return true;
}
elseif($status == "403"){
return false;
}
else{
return "error: $return";
}
}
else{
return "error: cURL not installed";
}
}
感谢您的帮助
Could anyone help me figure out how to post to tumblr using php.
I tried googling for a library or a sample code but couldn't find one. all I can find is this here https://github.com/alexdunae/tumblr-php/blob/master/Tumblr.php and it doesnt seem to work also I looked and tried the code on v1 api at tumblr website that doesnt work either ....
function post($data){
if(function_exists("curl_version")){
$data["email"] = $this->email;
$data["password"] = $this->password;
$data["generator"] = $this->generator;
$request = http_build_query($data);
$c = curl_init('http://www.tumblr.com/api/write');
curl_setopt($c,CURLOPT_POST,true);
curl_setopt($c,CURLOPT_POSTFIELDS,$request);
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
$return = curl_exec($c);
$status = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if($status == "201"){
return true;
}
elseif($status == "403"){
return false;
}
else{
return "error: $return";
}
}
else{
return "error: cURL not installed";
}
}
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚注意到这显示为 Tumblr 的精选,我想说的是:截至 2012 年,您应该忽略 Tuga 的上述答案,因为它不适用于最新的 Tumblr API。
您需要的是 TumblrOAuth ,它是由 OAuth 沙箱。
它仅用于读取和写入 Tumblr 帖子,因此如果您想要执行更多操作,则需要更改代码。我用它作为 Followr 的代码库。
I just noticed that this is showing up as Featured for Tumblr and I want to say this: As of 2012, you should IGNORE the above answer by Tuga because it DOES NOT work with the newest Tumblr API.
What you need is TumblrOAuth which is built from OAuth Sandbox.
It is only setup to read and write Tumblr posts, so if you want to do more than that, you'll need to alter the code. I used it as my code base for Followr.
盗自http://www.tumblr.com/docs/en/api
Stolen from http://www.tumblr.com/docs/en/api
此代码将允许您使用 tumblr API 向您的 tumblr 博客发布内容。
我希望这段代码有帮助。
This code will let you post to your tumblr blog using tumblr API.
I hope this code helps.
Tuga 提供的 api 示例正在为我工作(在 Wordpress 上)...所以我认为您的问题出在其他地方,而不是提供的示例。如果你们能发布第 2 版 api,我也将非常感激。
The api example provided by Tuga is working for me (on Wordpress)...so I think your problem lies elsewhere, and not with the example provided. I would also be very appreciative if you guys got a version 2 api working if you could post it.