Created
May 11, 2021 20:12
-
-
Save PLhery/4c82273e351540be327908c44698b322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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