Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

@0xindie/agent-twitter-client

Fork of agent-twitter-client with latest feature

crawlerscrapertwitterx
Published16 Nov 2024
Direct dependencies36
Transitive dependenciesNot calculated

README

Current package documentation

agent-twitter-client

This is a modified version of @the-convocation/twitter-scraper with added functionality for sending tweets and retweets. This package does not require the Twitter API to use and will run in both the browser and server.

Installation

npm install agent-twitter-client

Setup

Configure environment variables for authentication.

TWITTER_USERNAME=    # Account username
TWITTER_PASSWORD=    # Account password
TWITTER_EMAIL=       # Account email
PROXY_URL=           # HTTP(s) proxy for requests (necessary for browsers)

# Twitter API v2 credentials for tweet and poll functionality
TWITTER_API_KEY=               # Twitter API Key
TWITTER_API_SECRET_KEY=        # Twitter API Secret Key
TWITTER_ACCESS_TOKEN=          # Access Token for Twitter API v2
TWITTER_ACCESS_TOKEN_SECRET=   # Access Token Secret for Twitter API v2

Getting Twitter Cookies

It is important to use Twitter cookies to avoid sending a new login request to Twitter every time you want to perform an action.

In your application, you will likely want to check for existing cookies. If cookies are not available, log in with user authentication credentials and cache the cookies for future use.

const scraper = await getScraper({ authMethod: 'password' });

scraper.getCookies().then((cookies) => {
  console.log(cookies);
  // Remove 'Cookies' and save the cookies as a JSON array
});

Getting Started

const scraper = new Scraper();
await scraper.login('username', 'password');

// If using v2 functionality (currently required to support polls)
await scraper.login(
  'username',
  'password',
  'email',
  'appKey',
  'appSecret',
  'accessToken',
  'accessSecret',
);

const tweets = await scraper.getTweets('elonmusk', 10);
const tweetsAndReplies = scraper.getTweetsAndReplies('elonmusk');
const latestTweet = await scraper.getLatestTweet('elonmusk');
const tweet = await scraper.getTweet('1234567890123456789');
await scraper.sendTweet('Hello world!');

// Create a poll
await scraper.sendTweetV2(
  `What's got you most hyped? Let us know! 🤖💸`,
  undefined,
  {
    poll: {
      options: [
        { label: 'AI Innovations 🤖' },
        { label: 'Crypto Craze 💸' },
        { label: 'Both! 🌌' },
        { label: 'Neither for Me 😅' },
      ],
      durationMinutes: 120, // Duration of the poll in minutes
    },
  },
);

Fetching Specific Tweet Data (V2)

// Fetch a single tweet with poll details
const tweet = await scraper.getTweetV2('1856441982811529619', {
  expansions: ['attachments.poll_ids'],
  pollFields: ['options', 'end_datetime'],
});
console.log('tweet', tweet);

// Fetch multiple tweets with poll and media details
const tweets = await scraper.getTweetsV2(
  ['1856441982811529619', '1856429655215260130'],
  {
    expansions: ['attachments.poll_ids', 'attachments.media_keys'],
    pollFields: ['options', 'end_datetime'],
    mediaFields: ['url', 'preview_image_url'],
  },
);
console.log('tweets', tweets);

API

Authentication

// Log in
await scraper.login('username', 'password');

// Log out
await scraper.logout();

// Check if logged in
const isLoggedIn = await scraper.isLoggedIn();

// Get current session cookies
const cookies = await scraper.getCookies();

// Set current session cookies
await scraper.setCookies(cookies);

// Clear current cookies
await scraper.clearCookies();

Profile

// Get a user's profile
const profile = await scraper.getProfile('TwitterDev');

// Get a user ID from their screen name
const userId = await scraper.getUserIdByScreenName('TwitterDev');
import { SearchMode } from 'agent-twitter-client';

// Search for recent tweets
const tweets = scraper.searchTweets('#nodejs', 20, SearchMode.Latest);

// Search for profiles
const profiles = scraper.searchProfiles('John', 10);

// Fetch a page of tweet results
const results = await scraper.fetchSearchTweets('#nodejs', 20, SearchMode.Top);

// Fetch a page of profile results
const profileResults = await scraper.fetchSearchProfiles('John', 10);

Relationships

// Get a user's followers
const followers = scraper.getFollowers('12345', 100);

// Get who a user is following
const following = scraper.getFollowing('12345', 100);

// Fetch a page of a user's followers
const followerResults = await scraper.fetchProfileFollowers('12345', 100);

// Fetch a page of who a user is following
const followingResults = await scraper.fetchProfileFollowing('12345', 100);
// Get current trends
const trends = await scraper.getTrends();

// Fetch tweets from a list
const listTweets = await scraper.fetchListTweets('1234567890', 50);

Tweets

// Get a user's tweets
const tweets = scraper.getTweets('TwitterDev');

// Get a user's liked tweets
const likedTweets = scraper.getLikedTweets('TwitterDev');

// Get a user's tweets and replies
const tweetsAndReplies = scraper.getTweetsAndReplies('TwitterDev');

// Get tweets matching specific criteria
const timeline = scraper.getTweets('TwitterDev', 100);
const retweets = await scraper.getTweetsWhere(
  timeline,
  (tweet) => tweet.isRetweet,
);

// Get a user's latest tweet
const latestTweet = await scraper.getLatestTweet('TwitterDev');

// Get a specific tweet by ID
const tweet = await scraper.getTweet('1234567890123456789');

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 36

Native requirements
36 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@sinclair/typebox
Environment
{
  "local_name": "@sinclair/typebox",
  "alias": false,
  "peer_metadata": null
}
^0.32.20runtime
agent-twitter-client
Environment
{
  "local_name": "agent-twitter-client",
  "alias": false,
  "peer_metadata": null
}
^0.0.13runtime
headers-polyfill
Environment
{
  "local_name": "headers-polyfill",
  "alias": false,
  "peer_metadata": null
}
^3.1.2runtime
json-stable-stringify
Environment
{
  "local_name": "json-stable-stringify",
  "alias": false,
  "peer_metadata": null
}
^1.0.2runtime
otpauth
Environment
{
  "local_name": "otpauth",
  "alias": false,
  "peer_metadata": null
}
^9.2.2runtime
set-cookie-parser
Environment
{
  "local_name": "set-cookie-parser",
  "alias": false,
  "peer_metadata": null
}
^2.6.0runtime
tough-cookie
Environment
{
  "local_name": "tough-cookie",
  "alias": false,
  "peer_metadata": null
}
^4.1.2runtime
tslib
Environment
{
  "local_name": "tslib",
  "alias": false,
  "peer_metadata": null
}
^2.5.2runtime
twitter-api-v2
Environment
{
  "local_name": "twitter-api-v2",
  "alias": false,
  "peer_metadata": null
}
^1.18.2runtime
@commitlint/cli
Environment
{
  "local_name": "@commitlint/cli",
  "alias": false,
  "peer_metadata": null
}
^17.6.3development
@commitlint/config-conventional
Environment
{
  "local_name": "@commitlint/config-conventional",
  "alias": false,
  "peer_metadata": null
}
^17.6.3development
@tsconfig/node16
Environment
{
  "local_name": "@tsconfig/node16",
  "alias": false,
  "peer_metadata": null
}
^16.1.3development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
^29.5.1development
@types/json-stable-stringify
Environment
{
  "local_name": "@types/json-stable-stringify",
  "alias": false,
  "peer_metadata": null
}
^1.0.34development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^22.9.0development
@types/set-cookie-parser
Environment
{
  "local_name": "@types/set-cookie-parser",
  "alias": false,
  "peer_metadata": null
}
^2.4.2development
@types/tough-cookie
Environment
{
  "local_name": "@types/tough-cookie",
  "alias": false,
  "peer_metadata": null
}
^4.0.2development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
^5.59.7development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
^5.59.7development
dotenv
Environment
{
  "local_name": "dotenv",
  "alias": false,
  "peer_metadata": null
}
^16.4.5development
esbuild
Environment
{
  "local_name": "esbuild",
  "alias": false,
  "peer_metadata": null
}
^0.21.5development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^8.41.0development
eslint-config-prettier
Environment
{
  "local_name": "eslint-config-prettier",
  "alias": false,
  "peer_metadata": null
}
^8.8.0development
eslint-plugin-prettier
Environment
{
  "local_name": "eslint-plugin-prettier",
  "alias": false,
  "peer_metadata": null
}
^4.2.1development
gh-pages
Environment
{
  "local_name": "gh-pages",
  "alias": false,
  "peer_metadata": null
}
^5.0.0development
https-proxy-agent
Environment
{
  "local_name": "https-proxy-agent",
  "alias": false,
  "peer_metadata": null
}
^7.0.2development
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^29.7.0development
lint-staged
Environment
{
  "local_name": "lint-staged",
  "alias": false,
  "peer_metadata": null
}
^13.2.2development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
^2.8.8development
rimraf
Environment
{
  "local_name": "rimraf",
  "alias": false,
  "peer_metadata": null
}
^5.0.7development
rollup
Environment
{
  "local_name": "rollup",
  "alias": false,
  "peer_metadata": null
}
^4.18.0development
rollup-plugin-dts
Environment
{
  "local_name": "rollup-plugin-dts",
  "alias": false,
  "peer_metadata": null
}
^6.1.1development
rollup-plugin-esbuild
Environment
{
  "local_name": "rollup-plugin-esbuild",
  "alias": false,
  "peer_metadata": null
}
^6.1.1development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
^29.1.0development
typedoc
Environment
{
  "local_name": "typedoc",
  "alias": false,
  "peer_metadata": null
}
^0.24.7development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^5.0.4development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-6ATQXaW0AzPVrvzajP588QlIp+CCsgvrpXPdIoxRzUX46yAj+sRli9swoWYHLrEAV4EQWur6EVfanwgTIBqjJg==",
  "shasum": "b6de35d70cfced4aef89e34d1ea18e429e0d1ee6",
  "tarball": "https://registry.npmjs.org/@0xindie/agent-twitter-client/-/agent-twitter-client-1.0.0.tgz",
  "fileCount": 59,
  "unpackedSize": 1568094,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQCPCiSqJh5Udc9NhAt/bg3MOWxOr6E8tRnLARkfGZT/uwIgSczWNRjW+CwOsdhNl8Dcr9yGOPGSK1sT857H+082p7E="
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 08:56 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:739d8acb8aba3dfe1d99d82b9746f0f047d251c8b28259731a5cf2b096e7db09

Other collected versions

View all collected versions →