首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tumblr API上传

Tumblr API上传
EN

Stack Overflow用户
提问于 2011-03-25 23:27:17
回答 1查看 2.4K关注 0票数 3

也许我要疯了,但这不管用。我试图上传一个图片在连接文件夹到一个tumblr帐户。这是我的密码:

代码语言:javascript
复制
<?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

EN

回答 1

Stack Overflow用户

发布于 2012-02-17 06:45:38

只需添加以下代码:

代码语言:javascript
复制
// 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'
)
);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5439162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档