Tumblr API 上传
也许我要疯了,但这行不通。我正在尝试将连接文件夹中的图像上传到 tumblr 帐户。这是我的代码:
<?php
// Authorization info
$tumblr_email = '***';
$tumblr_password = '***';
// Data for new record
$post_type = 'photo';
$post_title = 'The post title';
$post_body = 'This is the body of the post.';
// Prepare POST request
$request_data = http_build_query(
array(
'email' => $tumblr_email,
'password' => $tumblr_password,
'type' => $post_type,
'data' => 'connect/19.jpg',
'generator' => 'testing'
)
);
// 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 ($status): $result\n";
}
?>
<img src="connect/19.jpg" />
我收到此错误:400
Maybe I am going crazy, but this isn't working. I am trying to upload a image in the connect folder to a tumblr account. Here's my code:
<?php
// Authorization info
$tumblr_email = '***';
$tumblr_password = '***';
// Data for new record
$post_type = 'photo';
$post_title = 'The post title';
$post_body = 'This is the body of the post.';
// Prepare POST request
$request_data = http_build_query(
array(
'email' => $tumblr_email,
'password' => $tumblr_password,
'type' => $post_type,
'data' => 'connect/19.jpg',
'generator' => 'testing'
)
);
// 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 ($status): $result\n";
}
?>
<img src="connect/19.jpg" />
I am getting this error: 400
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,您正在发送图像的路径,而不是图像本身。
更换怎么样
with
It seems to me like that you are sending a path to an image, not the image itself.
How about replacing
with
只需添加以下代码:
Just Add The below code: