Giter Club home page Giter Club logo

reddit-oauth's Introduction

Note: Not maintained

reddit-oauth

NPM version

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'
});

// Authenticate with username/password
reddit.passAuth(
    'your_reddit_username',
    'your_reddit_password',
    function (success) {
        if (success) {
            // Print the access token we just retrieved
            console.log(reddit.access_token);
        }
    }
);

// Get the OAuth URL to redirect users to
// Scopes are defined here: https://github.com/reddit/reddit/wiki/OAuth2
reddit.oAuthUrl('some_state', 'identity');

// After the user is redirected back to us, grab the query string
// object and exchange it for a set of access and refresh tokens.
// Scope has to be identical as the one provided to oAuthUrl. Can
// change for each authentication attempt.
reddit.oAuthTokens(
    'some_state',
    request.query,
    function (success) {
        // Print the access and refresh tokens we just retrieved
        console.log(reddit.access_token);
        console.log(reddit.refresh_token);
    }
);

// Returns true if access token exists
reddit.isAuthed();

// Force a refresh of the access token using the refresh token
reddit.refreshToken(
    function (success) {
        // Print the access token we just retrieved
        console.log(reddit.access_token);
    }
);

// Call authenticated GET endpoint
reddit.get(
    '/api/v1/me',
    {},
    function (error, response, body) {
        console.log(error);
        console.log(body);
    }
);

// Call authenticated GET listing endpoint with easy pagination
reddit.get(
    '/user/aihamh/submitted',
    {},
    function (error, response, body, next) {
        console.log(error);
        console.log(body);

        // next is not null, therefore there are more pages
        if (next) {
            next(); // Invoke next to retrieve the next page
        }
    }
);

// Call authenticated POST endpoint
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

reddit-oauth's People

Contributors

aiham avatar

Stargazers

İlim Albayrak avatar Hamidou TESSILIMI avatar Seth Sun avatar Bernardo Baquero Stand avatar John-Henry Liberty avatar  avatar Nikola Jokic avatar

Watchers

 avatar James Cloos avatar Timothy Dijamco avatar

reddit-oauth's Issues

It don't work.

So I've copied your tutorial code, and filled it in with my credentials.

const RedditApi = require('reddit-oauth');
let reddit = new RedditApi({
	app_id: 'id',
	app_secret: 'secret',
	redirect_uri: 'http://google.com/'
});

reddit.passAuth(
	user, //user and pass are variables with my credentials
	pass,
	function (success) {
		if (success) {
			comment_stream.start();
		} else {
			console.log(':(');
		}
	}
);

And whenever I run this, the :( pops up.

Browserify support

First of all, i've successfully used your package to authenticate and communicate with reddit api! Great job!

After reading source, it seems to me that there are no obstacles to run your package with browserify in the client side.

Did you have any plans on adding browserify support?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.