Reddit api sdk doing nothing, returns null

橙三吉。 提交于 2019-12-08 06:36:13

问题


I'm trying to use this reddit php api wrapper https://github.com/jcleblanc/reddit-php-sdk

To submit a post to reddit.

The code seems very simple, and I know I have it configured correct.

When I load the page, it will go to reddit, verify my account, then send me back. But doesn't make the post. If I refresh, nothing happens. If I delete the session cookie, it does the verification confirmation again, but never submits a post.

I set up the api, got the right app id and secret, the redirect uri is right, it comes back to my page.

<?php
echo '<h1>Test</h1>';

require_once("reddit.php");
$reddit = new reddit();

$title = "Test submission Google";
$link = "http://google.com/";
$subreddit = "truepixelart";
$response = $reddit->createStory($title, $link, $subreddit);

var_dump($response);
?>

the dump just returns null, so I don't know where to look

I know it's kind of obscure, but any ideas?


回答1:


A subreddit post will return null, based on my experience with the code from jcleblanc. His code is not working when i pulled it, but another person fixed it. Pull this https://github.com/markdavison/reddit-php-sdk/commit/2c2eac7f2202720e3fbb80b1ef48c87a6a213ff6

Then run that code. Except you are missing the getuser function which is required at all calls to the reddit api.

Other calls will return data, such as getlisting, etc and you will see posts submitted and the commands working.

If you need code, please ask as I have all basic functions coded.

Here is my subreddit code call with the git hub changes

ioudas@centralmainedesigns:~/centmedes/wordpress/reddit-php-sdk$ cat submitstory.php
<?php
require_once("reddit.php");
$reddit = new reddit();
$userData = $reddit->getUser();
$title = "MakerBot test 3 Releases IPad App For Easy 3D Printing";
$link = "http://makezine.com/greg";
$subreddit = "cbtest";
$response = $reddit->createStory($title, $link, $subreddit);
var_dump($response);
?>


来源:https://stackoverflow.com/questions/26198159/reddit-api-sdk-doing-nothing-returns-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!