36
loading...
This website collects cookies to deliver better user experience
This post is for day 1 of my #100DaysOfCode. In this post I'll be discussing how to programmatically tweet to Twitter using NodeJS.
yarn init -y
yarn add twitter-lite
yarn add dotenv
package.json
file should now look like this:{
"name": "programmatic-tweeting-with-nodejs",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"dot-env": "^0.0.1",
"twitter-lite": "^1.1.0"
}
}
.env
file should look like this:consumer_key = '<CONSUMER KEY>'
consumer_secret = '<CONSUMER SECRET>'
access_token_key = '<ACCESS TOKEN>'
access_token_secret = '<ACCESS TOKEN>'
<>
text with the tokens Twitter provided you.const twitter = require('twitter-lite')
require('dotenv').config()
const client = new twitter(config)
client
.post('statuses/update', { status: 'Hello World' })
.then(result => {
console.log('You successfully tweeted this : "' + result.text + '"')
})
.catch(console.error)
statuses/update
with the parameter status = 'Hello World'
.node index.js
into your terminal and press enter. This will generate a Tweet with the text "Hello World".36