如何使用 CURL 连接到 Tumblr API 并进行身份验证
我在使用经过身份验证的连接时偶然发现了问题。我不想检索带有特定标签的私人帖子。 目前,我收到状态 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
妈的,我自己搞定的……
Damnit, I got it by myself...