1

我偶然发现了使用经过身份验证的连接的问题。我不想检索带有特定标签的私人帖子。目前,我收到状态为 200 的错误消息为空,无法再做任何事情。代码(几乎与您的文档中相同:

$request_data = http_build_query(array('email'=>$thumblr['email'],'password'=>$thumblr['pass']));
//$c = curl_init("http://".$thumblr['acc_name'].".tumblr.com/api/read?tagged=".$thumblr['the_tag']);
$c = curl_init("http://www.tumblr.com/api/authenticate");
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);

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";
}

输出是:

Error [200]:

帮助?:)

4

1 回答 1

2

妈的,我自己弄的。。。

$request_data = http_build_query(
    array(
        'email'        =>$thumblr['email'],
        'password'  =>$thumblr['pass'],
        'id'             =>$thumblr['header_id'],
        'tagged'      =>$thumblr['the_tag']
    )
);
$c = curl_init('http://'.$thumblr['acc_name'].'.tumblr.com/api/read');
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);

switch ($status) {
    case '200': $msg = 'OK'; break;
    case '201': $msg = "Created - Success! The new post ID is $result.\n"; break;
    case '400': $msg = 'Bad Request - There was at least one error while trying to save your post.'; break;
    case '403': $msg = 'Forbidden - Your email address or password were incorrect.'; break;
    default: $msg = $result; break;
}
echo '<p>'.$msg.'</p><pre>'.print_r($result,1).'</pre>';
于 2011-04-07T11:35:18.740 回答