Skip to content

Instantly share code, notes, and snippets.

@PLhery
Created May 11, 2021 20:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PLhery/4c82273e351540be327908c44698b322 to your computer and use it in GitHub Desktop.
Save PLhery/4c82273e351540be327908c44698b322 to your computer and use it in GitHub Desktop.
import { TwitterApi } from 'twitter-api-v2';
const rl = require('readline');
const APP_INFOS = { appKey: 'XXX', appSecret: 'YYY' };
const readline = rl.createInterface({
input: process.stdin,
output: process.stdout
});
(async () => {
const { url, oauth_token, oauth_token_secret } = await new TwitterApi(APP_INFOS)
.generateAuthLink();
console.log('log in to ' + url);
const code = await new Promise(resolve => readline.question('Enter your code', resolve)) as string;
const client = new TwitterApi({...APP_INFOS, accessToken: oauth_token, accessSecret: oauth_token_secret });
const infos = await client.login(code)
console.log(infos);
})()
.catch((e) =>console.error('error', e.data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment