AI Personal Learning
and practical guidance
豆包Marscode1

agent-twitter-client: send and retweet tweets without Twitter API key

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.

agent-twitter-client:无需Twitter API密钥,发送、转发推文-1


 

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

  1. Cloning Project Warehouse:
   git clone https://github.com/elizaOS/agent-twitter-client.git
  1. Go to the project catalog:
   cd agent-twitter-client
  1. Install the dependencies:
   npm install

Configuring Environment Variables

In the project root directory, create a.envfile 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

  1. Send tweets and retweets: Users can be authenticated by configuring environment variables and then using thesendTweetmethod to send a tweet, or use thesendRetweetmethod for retweeting.
  2. Get Tweets: UsegetTweetsmethod to get tweets from a specific user.getTweetsAndRepliesmethod to get tweets and their replies.
  3. Get the latest tweets: UsegetLatestTweetmethod to get the latest tweets from a specific user.
  4. Using the Twitter API v2: By configuring keys and tokens for Twitter API v2, users can use thesendTweetV2method to send tweets with polling functionality.
  5. proxy request: Supports the configuration of thePROXY_URLenvironment variable to use the proxy for requests.
  6. Getting Twitter Cookies: UsegetCookiesmethod to get Twitter cookies to avoid frequent logins.
May not be reproduced without permission:Chief AI Sharing Circle " agent-twitter-client: send and retweet tweets without Twitter API key
en_USEnglish