mastodonclient
v1.1.6
Published
Simple Mastodon client
Downloads
12
Readme
mastodonclient
Minimal Mastodon client for my purposes. Does the OAuth dance and allows toots to be posted, home timeline to be fetched or generic API call to be made
Installation
npm install --save mastodonclient
Usage
One time only, you need to do the OAuth dance. This is an interactive process where you'll need to enter your Mastodon hostname, visit a URL and enter the code displayed at that URL back into the command line prompt.
const m = require('mastodonclient')
const config = await m.auth()
console.log(config)
The config
is a JS object that contains all the details required to authenticate you to make Mastodon API calls. Stash this away in a file somewhere.
If we have a config
object we can instantiate the MastodonClient
itself:
const mc = new m.MastodonClient(config)
This can be used to post toots:
// message, visibility, content warning
await mc.post('Who\'s there?', 'public', 'Knock knock')
fetch your timeline:
const timeline = await mc.home()
or do any other request:
const result = await mc.request({
method: 'get',
url: '/api/v1/timelines/home',
params: {
limit: 5
}
})
See the Mastodon API reference.