Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tumblr API Upload

Tags:

php

tumblr

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

like image 392
iosfreak Avatar asked Dec 29 '25 03:12

iosfreak


1 Answers

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'),
like image 137
Teo Klestrup Röijezon Avatar answered Dec 30 '25 17:12

Teo Klestrup Röijezon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!