Skip to content

Instantly share code, notes, and snippets.

@iogi
Created June 4, 2017 05:49
Show Gist options
  • Save iogi/8643b05840bcceedc2059baa98cb154d to your computer and use it in GitHub Desktop.
Save iogi/8643b05840bcceedc2059baa98cb154d to your computer and use it in GitHub Desktop.
get qiitadon access token using mastdon-api. fork from https://github.com/vanita5/mastodon-api/blob/master/examples/authorization.js
const readline = require('readline');
const Mastodon = require('mastodon-api');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let clientId;
let clientSecret;
const scope = 'read';
const baseUrl = 'https://qiitadon.com';
const apiEndpoint = `${baseUrl}/api/v1/apps`;
const clientName = 'client-name';
Mastodon.createOAuthApp(apiEndpoint, clientName, scope)
.catch(err => console.error(err))
.then((res) => {
console.log('Please save \'id\', \'client_id\' and \'client_secret\' in your program and use it from now on!');
console.log(res);
clientId = res.client_id;
clientSecret = res.client_secret;
return Mastodon.getAuthorizationUrl(clientId, clientSecret, baseUrl, scope);
})
.then((url) => {
console.log('This is the authorization URL. Open it in your browser and authorize with your account!');
console.log(url);
return new Promise((resolve) => {
rl.question('Please enter the code from the website: ', (code) => {
resolve(code);
rl.close();
});
});
})
.then(code => Mastodon.getAccessToken(clientId, clientSecret, code, baseUrl))
.catch(err => console.error(err))
.then((accessToken) => {
console.log(`This is the access token. Save it!\n${accessToken}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment