You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
working of code: I am making a twitter bot that tweet from my text file named as tweet.txt after fixed time interval using javascript language.
Code:
const Twitter = require('twitter-v2');
const fs = require('fs');
const client = new Twitter({
consumer_key:'',
consumer_secret:'',
access_token_key:'',
access_token_secret:'',
});
Error message"
C:\Users\HANZLA\Desktop\twitter_bot>node index.js
Posting tweet: "Opportunities multiply as they are seized." - The Art of War by Sun Tzu
Error posting tweet: TwitterError: Unauthorized
at module.exports.fromJson (C:\Users\HANZLA\Desktop\twitter_bot\node_modules\twitter-v2\build\TwitterError.js:23:16)
at Twitter.post (C:\Users\HANZLA\Desktop\twitter_bot\node_modules\twitter-v2\build\twitter.js:63:49)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async postTweet (C:\Users\HANZLA\Desktop\twitter_bot\index.js:19:22) {
code: 401,
details: 'Unauthorized'
}
I double check all the api keys and access token keys
this is what it gave in terminal when i update the twitter v-2
library
"up to date, audited 8 packages in 4s
2 high severity vulnerabilities
Some issues need review, and may require choosing
a different dependency."
The text was updated successfully, but these errors were encountered:
working of code: I am making a twitter bot that tweet from my text file named as tweet.txt after fixed time interval using javascript language.
Code:
const Twitter = require('twitter-v2');
const fs = require('fs');
const client = new Twitter({
consumer_key:'',
consumer_secret:'',
access_token_key:'',
access_token_secret:'',
});
function readTweetsFromFile() {
const tweets = fs.readFileSync('tweets.txt', 'utf8').split('\n');
return tweets.filter((tweet) => tweet.trim() !== '');
}
async function postTweet(tweet) {
console.log('Posting tweet:', tweet);
try {
console.log('client:', client);
console.log('client.tweets:', client.tweets);
console.log('client.tweets.createTweet:', client.tweets.createTweet);
const response = await client.tweet.createTweet({
text: tweet,
});
console.log('Tweet posted successfully:', response.data.text);
} catch (error) {
console.error('Error posting tweet:', error);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
const tweets = readTweetsFromFile();
const interval = 1000 * 60 * 60; // 1 hour
function tweetInterval() {
for (let i = 0; i < tweets.length; i++) {
setTimeout(() => {
postTweet(tweets[i]);
}, interval * i);
}
}
tweetInterval();
setInterval(tweetInterval, interval * tweets.length);
const Twitter = require('twitter-v2');
const fs = require('fs');
const client = new Twitter({
consumer_key:'',
consumer_secret:'',
access_token_key:'',
access_token_secret:'',
});
function readTweetsFromFile() {
const tweets = fs.readFileSync('tweets.txt', 'utf8').split('\n');
return tweets.filter((tweet) => tweet.trim() !== '');
}
async function postTweet(tweet) {
console.log('Posting tweet:', tweet);
try {
console.log('client:', client);
console.log('client.tweets:', client.tweets);
console.log('client.tweets.createTweet:', client.tweets.createTweet);
const response = await client.tweet.createTweet({
text: tweet,
});
console.log('Tweet posted successfully:', response.data.text);
} catch (error) {
console.error('Error posting tweet:', error);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
const tweets = readTweetsFromFile();
const interval = 1000 * 60 * 60; // 1 hour
function tweetInterval() {
for (let i = 0; i < tweets.length; i++) {
setTimeout(() => {
postTweet(tweets[i]);
}, interval * i);
}
}
tweetInterval();
setInterval(tweetInterval, interval * tweets.length);
Error message"
C:\Users\HANZLA\Desktop\twitter_bot>node index.js
Posting tweet: "Opportunities multiply as they are seized." - The Art of War by Sun Tzu
Error posting tweet: TwitterError: Unauthorized
at module.exports.fromJson (C:\Users\HANZLA\Desktop\twitter_bot\node_modules\twitter-v2\build\TwitterError.js:23:16)
at Twitter.post (C:\Users\HANZLA\Desktop\twitter_bot\node_modules\twitter-v2\build\twitter.js:63:49)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async postTweet (C:\Users\HANZLA\Desktop\twitter_bot\index.js:19:22) {
code: 401,
details: 'Unauthorized'
}
errro.txt
I double check all the api keys and access token keys
this is what it gave in terminal when i update the twitter v-2
library
"up to date, audited 8 packages in 4s
2 high severity vulnerabilities
Some issues need review, and may require choosing
a different dependency."
The text was updated successfully, but these errors were encountered: