Reddit API在php返回错误的captcha提交的故事



使用php为Reddit api提交一个故事返回错误的captcha。我能够使用api登录,并使用api完美地获得usermod和captcha。理想情况下,如果reddit_session cookie被传递,它应该发布而不是返回错误的captcha,有人能告诉我一些关于这个…

参考链接: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);
}
?>

对于那些最近偶然发现这个问题并且仍然有这个问题的人:

上述问题已修复,并正常工作,但如果您创建了一个新的帐户为您的reddit机器人,并试图提交一个故事,你会收到一个bad_captcha错误。新帐户必须提交验证码,直到他们获得一定数量的业力,所以这是你看到的错误。尝试使用旧的帐户请求,这应该可以解决您的问题。

据我所知,目前CAPTCHA在Reddit API中被打破了。他们最初使用过时的PyCAPTCHA,并正在迁移到reCAPTCHA。从那时起,使用api_type:json出现了一个问题,它有一个工作,github上的人目前正在工作。他还提供了一个解释/解决方案:

很简单,当需要>captcha时,json(虽然不是jquery)结果应该包含captcha_id。captcha_id是指完成url的部分,如下所示:>http://www.reddit.com/captcha/(captcha_id).png

我遇到的用例是当试图通过api使用>api_type:json提交一个故事。我很好地通知我不存在的captcha是不正确的,但是,我必须向http://www.reddit.com/api/new_captcha发出请求才能获得>captcha_id。这最后的往返似乎没有必要。

最新更新