如何使用 CURL 连接到 Tumblr API 并进行身份验证

发布于 2024-10-30 15:04:00 字数 848 浏览 6 评论 0原文

我在使用经过身份验证的连接时偶然发现了问题。我不想检索带有特定标签的私人帖子。 目前,我收到状态 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]:

帮助?:)

I stumbled upon problems using authenticated connection. I wan't to retrive private posts that are tagged with specific tag.
Currently, I am receiving status 200 with empty error message and can't do anything more.
The code (almost same as in your docs:

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

And output is:

Error [200]:

Help? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

十级心震 2024-11-06 15:04:01

妈的,我自己搞定的……

$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>';

Damnit, I got it by myself...

$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>';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文