我的网站过去常常使用以下代码将所有用户生成的作品提交到tumblr博客。 Tumblr现在已将他们的api更改为v2。任何有关更新下面的代码块以使用新版api的帮助都会受到极大的欢迎。感谢。
//submit to tumblr blog
// Authorization info
$tumblr_email = 'XXXXXXXXXX@drawaplanet.com';
$tumblr_password = 'XXXXXXXXXXX';
$post_type = 'photo';
$caption = $userCaption;
$post_title = '';
$post_body = '';
$source = 'http://www.drawaplanet.com/drawaplanet/gallery/' . $filename;
$click_through_url = 'http://www.drawaplanet.com/planet.php?s=' . $source;
// Prepare POST request
$request_data = http_build_query(
array(
'email' => $tumblr_email,
'password' => $tumblr_password,
'type' => $post_type,
'caption' => $caption,
'title' => $post_title,
'body' => $post_body,
'source' => $source,
'click-through-url' => $click_through_url,
'generator' => 'DRAWAPLANET'
)
);
// Send the POST request (with cURL)
$c = curl_init('http://www.tumblr.com/api/write');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $request_data);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($c);
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);