reddit-oauth
reddit-oauth is a wrapper around the Reddit API providing both OAuth and password authentication.
Requirements
Installation
npm install reddit-oauth
Documentation
http://aiham.github.io/reddit-oauth
Usage
var RedditApi = require('reddit-oauth');
var reddit = new RedditApi({
app_id: 'your_app_id',
app_secret: 'your_app_secret',
redirect_uri: 'your_app_redirect_uri'
});
reddit.passAuth(
'your_reddit_username',
'your_reddit_password',
function (success) {
if (success) {
console.log(reddit.access_token);
}
}
);
reddit.oAuthUrl('some_state', 'identity');
reddit.oAuthTokens(
'some_state',
request.query,
function (success) {
console.log(reddit.access_token);
console.log(reddit.refresh_token);
}
);
reddit.isAuthed();
reddit.refreshToken(
function (success) {
console.log(reddit.access_token);
}
);
reddit.get(
'/api/v1/me',
{},
function (error, response, body) {
console.log(error);
console.log(body);
}
);
reddit.get(
'/user/aihamh/submitted',
{},
function (error, response, body, next) {
console.log(error);
console.log(body);
if (next) {
next();
}
}
);
reddit.post(
'/api/comment',
{
api_type: 'json',
text: 'Hello World!',
thing_id: 'abc123'
},
function (error, response, body) {
console.log(error);
console.log(body);
}
);
Run Tests
Tests written with mocha.
Copy test/config.template.json
to test/config.json
and add your own app and user credentials. Then run:
npm test
Generate Documentation
Documentation can be generated with jsdoc by running:
npm run docs