5

使用 php for 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);
}
?>
4

2 回答 2

5

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

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

于 2012-07-10T06:54:36.750 回答
3

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

很简单,当需要 >captcha 时,json(尽管不是 jquery)结果应该包含 captcha_id。captcha_id 我的意思是完成如下网址的部分:>http://www.reddit.com/captcha/(captcha_id).png

我遇到的用例是尝试使用 >api_type:json 通过 api 提交故事。我很高兴知道我不存在的验证码不正确,但是,我 > 然后必须向http://www.reddit.com/api/new_captcha提出请求才能获得 >captcha_id。最后一次往返似乎没有必要。

于 2012-01-20T12:23:19.153 回答