AI个人学习
和实操指南
讯飞绘镜

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

综合介绍

agent-twitter-client是一个无需Twitter API密钥即可使用的Twitter客户端。该项目基于@the-convocation/twitter-scraper进行了修改,增加了发送推文和转推的功能。它可以在浏览器和服务器上运行,适用于需要自动化Twitter操作的用户。通过配置环境变量进行身份验证,用户可以轻松地发送推文、获取推文和进行其他Twitter操作。

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


 

功能列表

  • 发送推文和转推
  • 获取特定用户的推文
  • 获取推文及其回复
  • 获取最新推文
  • 使用Twitter API v2进行推文和投票功能
  • 支持代理请求
  • 获取Twitter Cookies以避免频繁登录

 

使用帮助

安装流程

  1. 克隆项目仓库:
   git clone https://github.com/elizaOS/agent-twitter-client.git
  1. 进入项目目录:
   cd agent-twitter-client
  1. 安装依赖:
   npm install

配置环境变量

在项目根目录下创建一个.env文件,并添加以下内容:

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访问令牌密钥

使用示例

获取推文

const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('你的用户名', '你的密码');
const tweets = await scraper.getTweets('elonmusk', 10);
console.log(tweets);
})();

发送推文

const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('你的用户名', '你的密码');
await scraper.sendTweet('Hello world!');
})();

获取最新推文

const { Scraper } = require('agent-twitter-client');
const scraper = new Scraper();
(async () => {
await scraper.login('你的用户名', '你的密码');
const latestTweet = await scraper.getLatestTweet('elonmusk');
console.log(latestTweet);
})();

详细功能介绍

  1. 发送推文和转推:用户可以通过配置环境变量进行身份验证,然后使用sendTweet方法发送推文,或使用sendRetweet方法进行转推。
  2. 获取推文:使用getTweets方法可以获取特定用户的推文,getTweetsAndReplies方法可以获取推文及其回复。
  3. 获取最新推文:使用getLatestTweet方法可以获取特定用户的最新推文。
  4. 使用Twitter API v2:通过配置Twitter API v2的密钥和令牌,用户可以使用sendTweetV2方法发送带有投票功能的推文。
  5. 代理请求:支持通过配置PROXY_URL环境变量来使用代理进行请求。
  6. 获取Twitter Cookies:使用getCookies方法获取Twitter Cookies,以避免频繁登录。
未经允许不得转载:首席AI分享圈 » agent-twitter-client:无需Twitter API密钥,发送、转发推文
zh_CN简体中文