gpt4 book ai didi

php - Tumblr API 上传

转载 作者:搜寻专家 更新时间:2023-10-31 20:53:10 27 4
gpt4 key购买 nike

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

最佳答案

在我看来,您发送的是图像的路径,而不是图像本身。
如何更换

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

关于php - Tumblr API 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5439162/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com