PHPでTumblrAPIを使って追加ブログに画像を投稿する方法
<?php // Authorization info $tumblr_email = 'メールアドレス'; $tumblr_password = 'パスワード'; $tumblr_groupe = 'http://(追加ブログID).tumblr.com/'; // Data for new record $post_type = 'photo'; $post_source = '画像アドレス'; $post_caption = 'HTML記述欄'; $post_click = '画像クリック時遷移URL'; // Prepare POST request $request_data = http_build_query( array( 'email' => $tumblr_email, 'password' => $tumblr_password, 'type' => $post_type, 'source' => $post_source, 'caption' => $post_caption, 'click-through-url' => $post_click, 'group' => $tumblr_groupe, 'generator' => 'API example' ) ); // 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); // Check for success if ($status == 201) { echo "Success! The new post ID is $result.\n"; } else if ($status == 403) { echo 'Bad email or password'; } else { echo "Error: $result\n"; }
Tumblrのメインブログとは別の「追加ブログ」(詳しくはコチラ参照http://www.tumblr.com/docs/ja/blogs)
この追加ブログに画像を投稿するphpコードです。
公式のAPI規約http://www.tumblr.com/docs/ja/apiのサンプルに少しだけ手を加えました。
(こっちは日本語訳Tumblr APIの使い方を勝手に和訳したもの元記事は削除してしまったらしいのでTumblr記事ですが)
HTML記述欄、画像クリック時遷移URLには元ページのアドレスとかを表示しておけば親切だと思われます。