PHP code example of rennokki / reddit-json-api
1. Go to this page and download the library: Download rennokki/reddit-json-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rennokki / reddit-json-api example snippets
use Rennokki\RedditApi\Reddit;
$app = Reddit::app(
'renoki-co/reddit-json-api',
'2.0',
'web',
'someusername'
);
$subreddit = Reddit::subreddit(
'funny', // subreddit name
$app
);
$posts = $subreddit->get();
foreach ($posts as $post) {
$id = $post['id'];
}
$subreddit = Reddit::subreddit('funny', $app);
$posts = $subreddit->get();
$nextPageOfPosts = $posts->nextPage();
public static $sorts = [
'hot', 'new', 'controversial', 'top', 'rising',
];
$subreddit = Reddit::subreddit('funny', $app);
$subreddit->sort('top');
public static $times = [
'hour', 'day', 'week', 'month', 'year', 'all',
];
$subreddit = Reddit::subreddit('funny', $app);
// Top, all time sorting.
$subreddit
->sort('top')
->time('all');
$subreddit = Reddit::subreddit('funny', $app);
$subreddit->setLimit(100);
$subreddit = Reddit::subreddit('funny', $app);
$subreddit
->setLimit(30)
->sort('top')
->time('week');
$url = $subreddit->getCallableUrl();