Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error code 410 error description unauthorized #103

Open
botdeveloper0 opened this issue Jun 3, 2023 · 0 comments
Open

error code 410 error description unauthorized #103

botdeveloper0 opened this issue Jun 3, 2023 · 0 comments

Comments

@botdeveloper0
Copy link

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant