0
我已經嘗試下面的代碼,發佈內容的tumblr
function upload_content(){
// Authorization info
$tumblr_email = '[email protected]';
$tumblr_password = 'secret';
// Data for new record
$post_type = 'text';
$post_title = 'Host';
$post_body = 'This is the body of the host.';
// Prepare POST request
$request_data = http_build_query(
array(
'email' => $tumblr_email,
'password' => $tumblr_password,
'type' => $post_type,
'title' => $post_title,
'body' => $post_body,
'generator' => 'API example'
)
);
// Send the POST request (with cURL)
$c = curl_init('api.tumblr.com/v2/blog/gurjotsinghmaan.tumblr.com/post');
//api.tumblr.com/v2/blog/{base-hostname}/post
//http://www.tumblr.com/api/write
//http://api.tumblr.com/v2/blog/{base-hostname}/posts/text?api_key={}
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";
}
}
什麼對此代碼不起作用?你得到什麼錯誤等?如果使用curl的cli版本手動向該端點提交請求,會發生什麼情況? – 2012-02-03 13:09:23
我提供了一些建議的網址, 我通過不同的URL獲得了不同的錯誤。像:壞電子郵件或通字 和無效的憑證等 – mrmaan4u 2012-02-04 06:41:53
請參考這個帖子[這裏] [1] [1]:http://stackoverflow.com/questions/7171750/post-to -tumblr-using-php/12142121#12142121 希望這會有所幫助。 – Eralph 2012-08-27 14:23:10