Download the PHP package tatter/reddit without Composer
On this page you can find all versions of the php package tatter/reddit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tatter/reddit
More information about tatter/reddit
Files in tatter/reddit
Package reddit
Short Description Reddit SDK for CodeIgniter 4
License MIT
Homepage https://github.com/tattersoftware/codeigniter4-reddit
Informations about the package reddit
codeigniter4-reddit
Reddit SDK for CodeIgniter 4
Quick Start
- Install with Composer:
> composer require tatter/reddit
- Supply Reddit credentials in .env
- Get API results:
Description
Reddit SDK provides a framework-ready wrapper to the API endpoints describe in the Reddit API documentation.
Configuration (optional)
The library's default behavior can be altered by extending its config file. Copy examples/Reddit.php to app/Config/ and follow the instructions in the comments. If no config file is found in app/Config then the library will use its own.
Credentials
This library requires a valid Reddit application to acquire access tokens that work with API. For more details read the Reddit OAuth2 wiki.
- Login to Reddit and visit the "authorized applications" page (https://www.reddit.com/prefs/apps/)
- Under "developed applications" select "create an app..."
- Select "script" as the application type
- Provide a name, description, and URLs in the required text fields
- Select "create app"
Once your application is created you will need to copy the "client ID" and "secret" (see the wiki article above for help). Add these along with your username and password into your project's .env file, for example:
Usage
The easiest way to access the client is via the CodeIgniter's Services:
$reddit = service('reddit');
The client will handle authentication (assuming your credentials are valid), rate limiting,
response filtering and formatting. Access client methods in chains to set up the request,
then use fetch()
to kick it off:
$comments = $reddit->subreddit('catgifs')->limit(10)->fetch('comments');
For more advanced needs you may use the request($uri, $data, $query)
method which returns
the actual Response
object, providing access to headers, etc. See also
HTTP/RedditRequest.php and HTTP/RedditResponse.php for some of the API handling
done "under the hood".
Troubleshooting
Should something go wrong all anticipated exceptions are wrapped in Tatter\Reddit\Exceptions\RedditException
,
so you can catch them and figure out what happened: