Php 将内容发布到Tumblr
我已经试过下面的代码了Php 将内容发布到Tumblr,php,tumblr,Php,Tumblr,我已经试过下面的代码了 function upload_content(){ // Authorization info $tumblr_email = 'email-address@host.com'; $tumblr_password = 'secret'; // Data for new record $post_type = 'text'; $post_title = 'Host'; $post_body = 'This
function upload_content(){
// Authorization info
$tumblr_email = 'email-address@host.com';
$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";
}
}
您需要使用正确的Tumblr端点: 我敢肯定其他人都不行
显然,要确保您的用户和密码是正确的,除此之外,这看起来很好——这正是我要写的。这段代码有什么不起作用?你会犯什么错误?如果您使用cli版本的curl手动向该端点提交请求,会发生什么情况?我提供了一些建议的url,通过不同的url会得到不同的错误。例如:错误的电子邮件或密码和无效的凭据等。请参阅此帖子[此处][1][1]:希望这对您有所帮助。