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=你的Twitter用户名
TWITTER_PASSWORD=你的Twitter密码
TWITTER_EMAIL=你的Twitter邮箱
PROXY_URL=你的代理URL(如果需要)
TWITTER_API_KEY=你的Twitter API密钥
TWITTER_API_SECRET_KEY=你的Twitter API密钥
TWITTER_ACCESS_TOKEN=你的Twitter访问令牌
TWITTER_ACCESS_TOKEN_SECRET=你的Twitter访问令牌密钥
usage example
Get Tweets
const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('你的用户名', '你的密码');
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('你的用户名', '你的密码');
await scraper.sendTweet('Hello world!');
})();
Get the latest tweets
const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('你的用户名', '你的密码');
const latestTweet = await scraper.getLatestTweet('elonmusk');
console.log(latestTweet);
})();
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.