Tumblr API 上传

发布于 2024-10-26 09:05:08 字数 1175 浏览 7 评论 0原文

也许我要疯了,但这行不通。我正在尝试将连接文件夹中的图像上传到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我只土不豪 2024-11-02 09:05:08

在我看来,您正在发送图像的路径,而不是图像本身。
更换怎么样

'data'              => 'connect/19.jpg',

with

'data'              => file_get_contents('connect/19.jpg'),

It seems to me like that you are sending a path to an image, not the image itself.
How about replacing

'data'              => 'connect/19.jpg',

with

'data'              => file_get_contents('connect/19.jpg'),

烟酉 2024-11-02 09:05:08

只需添加以下代码:

// Prepare POST request

$request_data = http_build_query(

array(

    'email'             => $tumblr_email,
    'password'          => $tumblr_password,
    'type'              => $post_type,
    'caption'           => $post_title,
    'data'              => file_get_contents('http://27.media.tumblr.com/tumblr_lywood4slh1qz7t0xo1_250.jpg'),
    'generator'         => 'testing'
)
);

Just Add The below code:

// Prepare POST request

$request_data = http_build_query(

array(

    'email'             => $tumblr_email,
    'password'          => $tumblr_password,
    'type'              => $post_type,
    'caption'           => $post_title,
    'data'              => file_get_contents('http://27.media.tumblr.com/tumblr_lywood4slh1qz7t0xo1_250.jpg'),
    'generator'         => 'testing'
)
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文