Introducing the Instagram APIRead more →

Guide · Node.js · Updated

Twitter Scraper for Node.js With No Login or Cookies

The popular Node.js Twitter scrapers sign in with your X account or its cookies, and their own README warns the account can be banned. Here is X data from one request, logged out.

The most used Twitter scraper on npm today is @the-convocation/twitter-scraper, ahead of rettiwt-api. Both read X the way its web app does, and for most data that means a signed-in session: you log in with an X account or export its ct0 and auth_token cookies. Its README is direct about the risk: "any account you log into with this library is subject to being banned at any time." Its issues show the other cost, requests that start failing with 404s (#165) or Cloudflare 403s (#158) until a fix ships.

This guide reads X with SocialTap from Node.js: profiles, an account's posts, a post's replies and keyword search, with no X account.

What a scraper login looks like

JavaScript
import { Scraper } from "@the-convocation/twitter-scraper";

const scraper = new Scraper();
await scraper.login(process.env.X_USERNAME, process.env.X_PASSWORD);
for await (const tweet of scraper.getTweets("nasa", 50)) {
  console.log(tweet.text);
}

Each run signs in an account you own. When X challenges it, asks for a code or suspends it, the job stops.

The same data with one API key

SocialTap reads what X shows a logged-out visitor, through its own sessions and proxies, and returns it in one schema. Install the SDK (ES modules, Node 20.3 or later):

Install
npm install socialtap

Get a key on the signup page and set it as SOCIALTAP_API_KEY. Every account starts with 100 free credits. This reads one profile:

TypeScript SDK
// Save this as app.mjs (an ES module) and run: node app.mjs
import { SocialTap } from "socialtap";

const client = new SocialTap(); // apiKey defaults to process.env.SOCIALTAP_API_KEY

const res = await client.x.profile.get({ handle: "NASA" });
console.log(res.data);
console.log(res.credits.charged, res.meta.request_id);

An account's posts

scraper.getTweets(name) becomes client.x.posts.iterate(), an async iterator over the account's posts, up to 100 a page, that stops at the guards you set:

TypeScript SDK
// Save this as app.mjs (an ES module) and run: node app.mjs
import { SocialTap, APIError, NotFoundError, PrivateOrUnavailableError } from "socialtap";

const client = new SocialTap(); // apiKey defaults to process.env.SOCIALTAP_API_KEY

try {
  // Stops at the end of the list, or at the first guard it reaches.
  const items = client.x.posts.iterate({ handle: "NASA" }, { maxPages: 10, maxCredits: 100 });
  for await (const item of items) {
    console.log(item);
  }
  console.log(items.pagesFetched, items.creditsCharged, items.stopReason, items.endReason);
} catch (err) {
  if (err instanceof NotFoundError) {
    // The item does not exist or was deleted.
    console.error(err.code, err.remediation);
  } else if (err instanceof PrivateOrUnavailableError) {
    // The item exists but isn't public: it is private, age- or region-restricted, or needs a login.
    console.error(err.code, err.remediation);
  } else if (err instanceof APIError) {
    // Retryable errors reach you only after the SDK's own retries. Failed requests cost no credits.
    console.error(err.code, err.status, err.retryable, err.remediation, err.requestId);
  } else throw err;
}

Each post has its full text, media, links and mentions, and its exact view, like, reply, repost, quote and bookmark counts. Logged out, X shows many organizations' timelines far back, newest first, and for most other accounts their most liked posts. sort picks between the two where X offers both.

Search posts by keyword

Keyword search is client.x.searchPosts.iterate(). X serves no search to logged-out visitors, so this endpoint finds posts through a web search engine's index of X. It finds what the index has crawled and ends after a few pages: for one account's posts, use the posts endpoint above.

From twitter-scraper to SocialTap

twitter-scraperSocialTapEndpoint
scraper.getProfile(name)client.x.profile.get()X (Twitter) Profile API
scraper.getTweets(name, n)client.x.posts.iterate()X (Twitter) User Posts API
scraper.getTweet(id)client.x.post.get()X (Twitter) Post API
scraper.searchTweets(query, n)client.x.searchPosts.iterate()X (Twitter) Post Search API

Replies to a post, the conversation under it, are client.x.comments.iterate().

What it costs

You pay per successful request, and a list request returns a page:

  • An account's posts: $0.0075–$0.02 per 1,000 posts.
  • Profiles: $0.75–$1.97 per 1,000 profiles.

Failed requests and cache hits cost nothing. The X (Twitter) API page sets X's own per-post prices beside ours.

Frequently asked questions

Can I scrape Twitter without logging in?

Yes, the public part. SocialTap reads profiles, posts and the replies X shows a logged-out visitor. Scrapers on npm mostly sign in because X shows less to logged-out visitors, and that puts the account at risk.

Back to contents

Will my X account get banned?

Not with SocialTap: no account of yours is used. With a library that signs in, its own README says the account "is subject to being banned at any time".

Back to contents

Does it run on Vercel or Cloudflare Workers?

Yes. The SDK uses fetch and nothing else, so it runs in Node, Deno, Bun, Vercel functions and Cloudflare Workers, with your key kept on the server.

Back to contents

How is this different from the official X API?

X's API charges for each post it returns, from prepaid credits, after you create an app. SocialTap needs an API key only, and a list request returns a page of posts for the price of one request.

Back to contents

Replace twitter-scraper with one API key.

Get a key, run the code above and see live data in a minute. Failed requests are free.

100free credits
  • No credit card
  • Failed requests are free
  • Works on all 310 endpoints
Start for free Read the docs