Ram*_*mji 5 php api reddit httprequest
使用php for Reddit api提交故事会将错误的验证码作为错误返回.我能够使用api登录并使用api完美地获取usermod和captcha.理想情况下,如果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);
}
?>
Run Code Online (Sandbox Code Playgroud)
小智 5
对于最近偶然发现这个问题并且仍然遇到这个问题的其他人:
上述问题已修复并正常工作,但如果您为reddit bot创建了一个新帐户并尝试提交故事,则会收到bad_captcha错误.新帐户必须提交验证码,直到他们获得一定数量的业力,因此这是您看到的错误.尝试使用较旧的帐户请求,这应该可以解决您的问题.
据我所知,目前 Reddit API 中的验证码已被破坏。他们最初使用过时的 PyCAPTCHA,并正在迁移到 reCAPTCHA。从那时起,使用 which 就出现了一个问题api_type:json,有一个解决方法,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。最后一次往返似乎没有必要。