stackers
stackers

Reputation: 3279

Reddit api sdk doing nothing, returns null

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?

Upvotes: 1

Views: 742

Answers (1)

user169797
user169797

Reputation:

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);
?>

Upvotes: 2

Related Questions