PHP 中的 Reddit API 在提交故事时返回错误的验证码
使用 php Reddit api 提交故事会返回错误的验证码作为错误。 我可以使用 api 登录并使用 api 完美获取 usermod 和验证码。 理想情况下,如果 reddit_session cookie 被传递,它应该发布并且不会返回错误的验证码有人可以告诉我一些关于这个的信息..
参考链接: https://github.com/reddit/reddit/wiki/API
<?php
$user = "";
$passwd = "";
$url = "http://www.reddit.com/api/login/".$user;
$r = new HttpRequest($url, HttpRequest::METH_POST);
$r->addPostFields(array('api_type' => 'json', 'user' => $user, 'passwd' => $passwd));
try {
$send = $r->send();
$userinfo = $send->getBody();
} catch (HttpException $ex) {
echo $ex;
}
$arr = json_decode($userinfo,true);
$modhash = $arr['json']['data']['modhash'];
$reddit_session = $arr['json']['data']['cookie'];
$post = array('uh'=>$modhash,
'kind'=>'link',
'url'=>'yourlink.com',
'sr'=>'funny',
'title'=>'omog-asdfasf',
'id'=>'newlink',
'r'=>'funnyier',
'renderstyle'=> 'html'
);
$url = "http://www.reddit.com/api/submit";
// Upvote RoboHobo's comment :)
// Add user cookie data
$r->addCookies(array("reddit_session" => $reddit_session));
// Set URL to vote
$r->setUrl($url);
// Add vote information, found at http://wiki.github.com/talklittle/reddit-is-fun/api-all-functions
$r->setPostFields($post);
// Send request blindly
try {
$userinfo = $r->send();
} catch (HttpException $ex) {
echo $ex;
}
pre($userinfo);
exit;
function pre($r){
echo "<pre />";
print_r($r);
}
?>
Using php for Reddit api for submitting a story returns bad captcha as error.
I am able to login using the api and get usermod and captcha perfectly using api.
Ideally if the reddit_session cookie is passed it should post and not return bad captcha can someone shed me some light on this..
reference link:
https://github.com/reddit/reddit/wiki/API
<?php
$user = "";
$passwd = "";
$url = "http://www.reddit.com/api/login/".$user;
$r = new HttpRequest($url, HttpRequest::METH_POST);
$r->addPostFields(array('api_type' => 'json', 'user' => $user, 'passwd' => $passwd));
try {
$send = $r->send();
$userinfo = $send->getBody();
} catch (HttpException $ex) {
echo $ex;
}
$arr = json_decode($userinfo,true);
$modhash = $arr['json']['data']['modhash'];
$reddit_session = $arr['json']['data']['cookie'];
$post = array('uh'=>$modhash,
'kind'=>'link',
'url'=>'yourlink.com',
'sr'=>'funny',
'title'=>'omog-asdfasf',
'id'=>'newlink',
'r'=>'funnyier',
'renderstyle'=> 'html'
);
$url = "http://www.reddit.com/api/submit";
// Upvote RoboHobo's comment :)
// Add user cookie data
$r->addCookies(array("reddit_session" => $reddit_session));
// Set URL to vote
$r->setUrl($url);
// Add vote information, found at http://wiki.github.com/talklittle/reddit-is-fun/api-all-functions
$r->setPostFields($post);
// Send request blindly
try {
$userinfo = $r->send();
} catch (HttpException $ex) {
echo $ex;
}
pre($userinfo);
exit;
function pre($r){
echo "<pre />";
print_r($r);
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
据我所知,目前 Reddit API 中的验证码已被破坏。他们最初使用过时的 PyCAPTCHA,并迁移到 reCAPTCHA。从那时起,使用 api_type:json 就出现了问题 code> 有一个解决办法,github 上有人正在处理它。他还提供了一个解释/解决方案:
很简单,当需要 > captcha 时,json(尽管不是 jquery)结果应包含 captcha_id。我所说的 captcha_id 是指完成如下 url 的部分:>http://www.reddit.com/captcha/(captcha_id).png
我遇到的用例是尝试使用 >api_type:json 通过 api 提交故事时。我很好地得知我不存在的验证码不正确,但是,我>然后必须向 http://www.reddit.com/api/new_captcha 以获得>captcha_id。最后一次往返似乎没有必要。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
对于最近偶然发现这个问题并且仍然遇到该问题的其他人:
上述问题已修复并且可以正常工作,但是如果您为 Reddit 机器人创建了一个新帐户并尝试提交故事,您将收到 bad_captcha 错误。新帐户必须提交验证码,直到获得一定量的业力,所以这就是您看到的错误。使用旧帐户尝试该请求,这应该可以解决您的问题。
For anyone else that stumbled onto this question lately and is still having that issue:
The above issue was fixed and works correctly however if you created a new account for your reddit bot and try to submit a story you will recieve a bad_captcha error. New accounts have to submit captchas until they gain a certain amount of karma so this is the error you are seeing. Try the request with an older account and this should solve your problem.