
I have been trying to figure out how to build a Twitter bot for a while. I had it almost done, then Elon went and wrecked their API for no good reason and I had to start over. Their API is a complete mess and makes me appreciate the simplicity of the Manifold one much more. I'm really tired of dealing with it.
I don't need anything fancy, I just want a Javascript function that I can call with my API key/secret and will immediately post a top-level tweet. Installing an npm library is fine. M$500 to the first person who provides such a function that just works with no additional fiddling necessary.
geeksforgeeks also has a decent tutorial:
https://www.geeksforgeeks.org/tweet-using-node-js-and-twitter-api/
const { TwitterApi } = require('twitter-api-v2');
async function postTweet(content, apiKey, apiSecret, accessToken, accessSecret) {
const client = new TwitterApi({
appKey: apiKey,
appSecret: apiSecret,
accessToken: accessToken,
accessSecret: accessSecret,
});
try {
const tweet = await client.v2.tweet(content);
console.log("Tweet posted successfully:", tweet);
} catch (error) {
console.error("Error posting tweet:", error);
}
}
// Usage
const apiKey = 'YOUR_API_KEY';
const apiSecret = 'YOUR_API_SECRET';
const accessToken = 'YOUR_ACCESS_TOKEN';
const accessSecret = 'YOUR_ACCESS_SECRET';
postTweet("Hello, Twitter!", apiKey, apiSecret, accessToken, accessSecret);