Skip to content

matiasngf/twitter-api-scraper

Repository files navigation

twitter-api-scraper

Get typed data from the public twitter api. No keys required.

NPM JavaScript Style Guide License Issues

  • Search tweets
  • Get users by username
  • Get users by id
  • Get hashflags
  • Get tweets from user
  • Get replies from tweet
  • Get trending topics

Install

npm install --save twitter-api-scraper

Usage

Start client

First, connect() the client.

import TwitterClient from 'twitter-api-scraper'
const client = new TwitterClient()
await client.connect()

Search

const maxTweets = 3000
const result = await client.search(
  {
    terms: 'hello world!'
  },
  maxTweets
)

const { tweets, users, nextToken } = result

Typescript

import { SearchQuery, ParsedSearchResult } from 'twitter-api-scraper'

const query: SearchQuery = {
  terms: '#typescript',
  dateFrom: '2021-02-15',
  dateTo: '2021-02-15'
}

const result: ParsedSearchResult = await client.search(query)

Search parameters

const query: SearchQuery = {
  terms: '#typescript',
  dateFrom: '2021-02-15',
  dateTo: '2021-02-17',
  minReplies: 10,
  minRetweets: 10,
  minFaves: 10,
  lang: 'es'
}
client.search(query)

Search multiple pages

const result = await client.search(query, 100)
const { nextToken } = result

const secondPageResult = await client.search(query, 100, nextToken)

Original api response

const originalApiResult = await client.searchRaw(
  {
    terms: 'hello world!'
  }
)

Users

Get user

const user: UserInterface = await client.getUser('jack')

Get user by id

const user: UserFromId = await client.getUserById('12')

Hashflags

const hashflags: Hashflag[] = await client.getHashflags('2021-09-23')

License

MIT © matiasngf