@nickacide/redditjs v0.0.1
RedditJS
RedditJS is a JavaScript library for interacting with Reddit's official API. Not only is it lightweight, it's also easy to use.
Install
Install via npm:
npm install --save js-redditRedditJS requires events and request-promise as dependencies.
Features
- 100% Promise-based
- Full coverage of Reddit's
API - Extremely lightweight
- Feels intuitive to use
Setup
To get started, you need to create an app. To understand how Reddit apps work, I suggest reading about it here.
Instructions:
- Create your app on Reddit (Either
Web ApporScript). - Follow the next steps here.
- Acquire your
refresh token,client idandclient secret.
Usage
Now that you have everything you need, you can start writing some code. Here is an example for posting a link on Reddit.
const Reddit = require('js-reddit');
const client = new Reddit.Client({
refresh_token: "refresh token",
secret: "client secret",
id: "client id"
});
client.on('authorized', () => {
console.log(`Logged in! My token is ${client.token}`)
})
client.authenticate();
client.post('/api/submit', {
sr: 'memes',
resubmit: true,
kind: 'link',
title: 'Title for my Link',
url: 'https://www.example.com'
}).then(results => {
console.log(results)
});Expected Output
{
json: {
errors: [],
data: {
url: 'link to message on reddit',
drafts_count: 0,
id: 'unique-ID',
name: 't3_unique-ID'
}
}
}Documentation
At the time of this writing, no Documentation exists yet, as this package lacks features. For now, the functionality of this package will be shown here. *Code is case-sensitive.
Client extends EventEmitter
Properties
Client.idThe id of the app you createdClient.secretThe secret of your appClient.refresh_tokenThe token used to generate access tokensClient.tokenThe access token (Regenerated every 3950 seconds)Client.user_agent(Optional) Your User Agent. Always try provide one.MethodsClient.authenticate()Authorize your app and generate an access tokenClient.get(path, options)wherepath: The api path you want to invoke,options: The options required for the requestClient.put(path, options)wherepath: The api path you want to invoke,options: The options required for the requestClient.post(path, options)wherepath: The api path you want to invoke,options: The options required for the requestClient.patch(path, options)wherepath: The api path you want to invoke,options: The options required for the requestClient.delete(path, options)wherepath: The api path you want to invoke,options: The options required for the requestEventsauthorizedEmitted when theClientsuccessfully authenticated.
FAQ
Questions can be asked by creating an Issue or asking in my Discord server. If you have a suggestion, please tell me! I am not online everyday, so do not expect the fastest responses. If you would like to become a contributor for this repository or a mod in my Discord server, simply ask!
5 years ago