General Introduction
agent-twitter-client is a Twitter client that works without a Twitter API key. The project is based on @the-convocation/twitter-scraper modified to add the ability to send tweets and retweets. It runs on both browsers and servers and is suitable for users who need to automate Twitter operations. By configuring environment variables for authentication, users can easily send tweets, get tweets and perform other Twitter operations.
Function List
- Send tweets and retweets
- Get tweets from specific users
- Get tweets and their replies
- Get the latest tweets
- Tweets and Polling Functionality with Twitter API v2
- Support for proxy requests
- Get Twitter Cookies to Avoid Frequent Logins
Using Help
Installation process
- Cloning Project Warehouse:
git clone https://github.com/elizaOS/agent-twitter-client.git
- Go to the project catalog:
cd agent-twitter-client
- Install the dependencies:
npm install
Configuring Environment Variables
In the project root directory, create a.env
file and add the following:
TWITTER_USERNAME=your Twitter username
TWITTER_PASSWORD=Your Twitter password.
TWITTER_EMAIL=your Twitter email address
PROXY_URL=Your proxy URL (if needed)
TWITTER_API_KEY=your Twitter API key
TWITTER_API_SECRET_KEY=your Twitter API key
TWITTER_ACCESS_TOKEN=your Twitter access token
TWITTER_ACCESS_TOKEN_SECRET=your Twitter access token key
usage example
Get Tweets
const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('Your username', 'Your password');
const tweets = await scraper.getTweets('elonmusk', 10);
console.log(tweets);
})();
Send a tweet
const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('your username', 'your password'); await scraper.sendTweet('Hello world'); const scraper = new scraper() => {
await scraper.sendTweet('Hello world!');
})();
Get the latest tweets
const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('your username', 'your password');
const latestTweet = await scraper.getLatestTweet('elonmusk');
})();
Detailed Functions
- Send tweets and retweets: Users can be authenticated by configuring environment variables and then using the
sendTweet
method to send a tweet, or use thesendRetweet
method for retweeting. - Get Tweets: Use
getTweets
method to get tweets from a specific user.getTweetsAndReplies
method to get tweets and their replies. - Get the latest tweets: Use
getLatestTweet
method to get the latest tweets from a specific user. - Using the Twitter API v2: By configuring keys and tokens for Twitter API v2, users can use the
sendTweetV2
method to send tweets with polling functionality. - proxy request: Supports the configuration of the
PROXY_URL
environment variable to use the proxy for requests. - Getting Twitter Cookies: Use
getCookies
method to get Twitter cookies to avoid frequent logins.