Skip to content
This repository
branch: master

Merge pull request #10 from samnabi/master

Added getSaved function
latest commit c38e5624ad
Jonathan LeBlanc authored
Octocat-spinner-32 README.textile Update README.textile January 20, 2013
Octocat-spinner-32 reddit.php Added getSaved function December 09, 2012
README.textile

Reddit PHP SDK

The Reddit SDK is a wrapper around the Reddit APIs: https://github.com/reddit/reddit/wiki/API

Initiating Your Login Session

Before making requests to any of the methods of the Reddit SDK, you first need to authenticate by calling the login method with your username and password. This will populate your user hash and session data.

require_once("reddit.php");
$reddit = new reddit("USERNAME", "PASSWORD");

SDK Methods

Once you are authenticated, you may then make requests to any of the methods in the SDK.

Creating a New Story

$title = "British coffee-powered car breaks world record";
$link = "http://www.extremetech.com/extreme/97287-british-coffee-powered-car-breaks-world-record";
$subreddit = "technology"
$response = $reddit->createStory($title, $link, $subreddit);

Get User Information

$userData = $reddit->getUser();

Get User Subscriptions

$subscriptions = $reddit->getSubscriptions();

Get Page Information

$pageInfo = $reddit->getPageInfo("http://i.imgur.com/QxdCd.jpg");

Save Story

$response = $reddit->savePost("t3_n6ocq"));

Unsave Story

$response = $reddit->unsavePost("t3_n6ocq");

Hide Post

$response = $reddit->hidePost("t3_n6ocq"));

Unhide Post

$response = $reddit->unhidePost("t3_n6ocq");

Get Posts

$response = $reddit->getListing("technology", 5);

Get Saved User Posts

$response = $reddit->getSaved("USERNAME");

Get Raw JSON

$response = $reddit->getRawJSON("/r/funny/comments/12ma0a/this_guy_showed_up_at_our_party_last_night_didnt/");
//get the JSON for the top technology post
$response1 = $reddit->getListing("technology", 1);
$response2 = $reddit->getRawJSON($response1->data->children[0)]->data->permalink);

Share Post

$response = $reddit->sharePost("t3_jp2k7", "Jon", "me@mysite.com", "you@yoursite.com", "Check out this post");

Add Comment

$response = $reddit->addComment("t3_jp2k7", "Hey!\n\n**[search!](http://www.google.com/)**");

Add Vote

$response = $reddit->addVote("t3_n6ocq", 1);

Set or Clear a User’s Flair in a Subreddit

$response = $reddit->setFlair("motorcycles", "jcleblanc", "ZZR600", "kawasaki");

Download the Flair Assignments of a Subreddit

$response = $reddit->getFlairList("motorcycles", 100, "t2_39qab", "t2_39qab");

Post a CSV File of Flair Settings to a Subreddit

$response = $reddit->setFlairCSV("motorcycles", "jcleblanc,ZZR600,kawasaki\n...");
Something went wrong with that request. Please try again.