PHP 中的 Reddit API 在提交故事时返回错误的验证码

发布于 12-04 14:01 字数 1660 浏览 1 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的背包2024-12-11 14:01:29

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

上述问题已修复并且可以正常工作,但是如果您为 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.

寂寞笑我太脆弱2024-12-11 14:01:29

据我所知,目前 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。最后一次往返似乎没有必要。

From what I can tell, at the moment CAPTCHA is broken in the Reddit API. They originally were using an outdated PyCAPTCHA and were migrating to reCAPTCHA. Since then, there has been an issue with using api_type:json which has a work around and someone on github is currently working it. He also offered an explanation/solution:

Quite simply, the json (though not jquery) result should contain the captcha_id when a >captcha is required. By captcha_id I mean the part to complete a url like the followng: >http://www.reddit.com/captcha/(captcha_id).png

The use case I encountered is when trying to submit a story via the api using >api_type:json. I am nicely notified that my non-existent captcha is incorrect, however, I >then have to make a request to http://www.reddit.com/api/new_captcha in order to get the >captcha_id. This last round trip seems unnecessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文