import { Cookie } from 'tough-cookie'; import { FetchTransformOptions } from './api'; import { Profile } from './profile'; import { SearchMode } from './search'; import { QueryProfilesResponse, QueryTweetsResponse } from './timeline-v1'; import { Tweet, TweetQuery } from './tweets'; import fetch from 'cross-fetch'; export interface ScraperOptions { /** * An alternative fetch function to use instead of the default fetch function. This may be useful * in nonstandard runtime environments, such as edge workers. */ fetch: typeof fetch; /** * Additional options that control how requests and responses are processed. This can be used to * proxy requests through other hosts, for example. */ transform: Partial; } /** * An interface to Twitter's undocumented API. * - Reusing Scraper objects is recommended to minimize the time spent authenticating unnecessarily. */ export declare class Scraper { private readonly options?; private auth; private authTrends; private token; /** * Creates a new Scraper object. * - Scrapers maintain their own guest tokens for Twitter's internal API. * - Reusing Scraper objects is recommended to minimize the time spent authenticating unnecessarily. */ constructor(options?: Partial | undefined); /** * Fetches a Twitter profile. * @param username The Twitter username of the profile to fetch, without an `@` at the beginning. * @returns The requested {@link Profile}. */ getProfile(username: string): Promise; /** * Fetches the user ID corresponding to the provided screen name. * @param screenName The Twitter screen name of the profile to fetch. * @returns The ID of the corresponding account. */ getUserIdByScreenName(screenName: string): Promise; /** * Fetches tweets from Twitter. * @param query The search query. Any Twitter-compatible query format can be used. * @param maxTweets The maximum number of tweets to return. * @param includeReplies Whether or not replies should be included in the response. * @param searchMode The category filter to apply to the search. Defaults to `Top`. * @returns An {@link AsyncGenerator} of tweets matching the provided filters. */ searchTweets(query: string, maxTweets: number, searchMode?: SearchMode): AsyncGenerator; /** * Fetches profiles from Twitter. * @param query The search query. Any Twitter-compatible query format can be used. * @param maxProfiles The maximum number of profiles to return. * @returns An {@link AsyncGenerator} of tweets matching the provided filter(s). */ searchProfiles(query: string, maxProfiles: number): AsyncGenerator; /** * Fetches tweets from Twitter. * @param query The search query. Any Twitter-compatible query format can be used. * @param maxTweets The maximum number of tweets to return. * @param includeReplies Whether or not replies should be included in the response. * @param searchMode The category filter to apply to the search. Defaults to `Top`. * @param cursor The search cursor, which can be passed into further requests for more results. * @returns A page of results, containing a cursor that can be used in further requests. */ fetchSearchTweets(query: string, maxTweets: number, searchMode: SearchMode, cursor?: string): Promise; /** * Fetches profiles from Twitter. * @param query The search query. Any Twitter-compatible query format can be used. * @param maxProfiles The maximum number of profiles to return. * @param cursor The search cursor, which can be passed into further requests for more results. * @returns A page of results, containing a cursor that can be used in further requests. */ fetchSearchProfiles(query: string, maxProfiles: number, cursor?: string): Promise; /** * Fetches list tweets from Twitter. * @param listId The list id * @param maxTweets The maximum number of tweets to return. * @param cursor The search cursor, which can be passed into further requests for more results. * @returns A page of results, containing a cursor that can be used in further requests. */ fetchListTweets(listId: string, maxTweets: number, cursor?: string): Promise; /** * Fetch the profiles a user is following * @param userId The user whose following should be returned * @param maxProfiles The maximum number of profiles to return. * @returns An {@link AsyncGenerator} of following profiles for the provided user. */ getFollowing(userId: string, maxProfiles: number): AsyncGenerator; /** * Fetch the profiles that follow a user * @param userId The user whose followers should be returned * @param maxProfiles The maximum number of profiles to return. * @returns An {@link AsyncGenerator} of profiles following the provided user. */ getFollowers(userId: string, maxProfiles: number): AsyncGenerator; /** * Fetches following profiles from Twitter. * @param userId The user whose following should be returned * @param maxProfiles The maximum number of profiles to return. * @param cursor The search cursor, which can be passed into further requests for more results. * @returns A page of results, containing a cursor that can be used in further requests. */ fetchProfileFollowing(userId: string, maxProfiles: number, cursor?: string): Promise; /** * Fetches profile followers from Twitter. * @param userId The user whose following should be returned * @param maxProfiles The maximum number of profiles to return. * @param cursor The search cursor, which can be passed into further requests for more results. * @returns A page of results, containing a cursor that can be used in further requests. */ fetchProfileFollowers(userId: string, maxProfiles: number, cursor?: string): Promise; /** * Fetches the current trends from Twitter. * @returns The current list of trends. */ getTrends(): Promise; /** * Fetches tweets from a Twitter user. * @param user The user whose tweets should be returned. * @param maxTweets The maximum number of tweets to return. Defaults to `200`. * @returns An {@link AsyncGenerator} of tweets from the provided user. */ getTweets(user: string, maxTweets?: number): AsyncGenerator; /** * Fetches tweets from a Twitter user using their ID. * @param userId The user whose tweets should be returned. * @param maxTweets The maximum number of tweets to return. Defaults to `200`. * @returns An {@link AsyncGenerator} of tweets from the provided user. */ getTweetsByUserId(userId: string, maxTweets?: number): AsyncGenerator; /** * Fetches the first tweet matching the given query. * * Example: * ```js * const timeline = scraper.getTweets('user', 200); * const retweet = await scraper.getTweetWhere(timeline, { isRetweet: true }); * ``` * @param tweets The {@link AsyncIterable} of tweets to search through. * @param query A query to test **all** tweets against. This may be either an * object of key/value pairs or a predicate. If this query is an object, all * key/value pairs must match a {@link Tweet} for it to be returned. If this query * is a predicate, it must resolve to `true` for a {@link Tweet} to be returned. * - All keys are optional. * - If specified, the key must be implemented by that of {@link Tweet}. */ getTweetWhere(tweets: AsyncIterable, query: TweetQuery): Promise; /** * Fetches all tweets matching the given query. * * Example: * ```js * const timeline = scraper.getTweets('user', 200); * const retweets = await scraper.getTweetsWhere(timeline, { isRetweet: true }); * ``` * @param tweets The {@link AsyncIterable} of tweets to search through. * @param query A query to test **all** tweets against. This may be either an * object of key/value pairs or a predicate. If this query is an object, all * key/value pairs must match a {@link Tweet} for it to be returned. If this query * is a predicate, it must resolve to `true` for a {@link Tweet} to be returned. * - All keys are optional. * - If specified, the key must be implemented by that of {@link Tweet}. */ getTweetsWhere(tweets: AsyncIterable, query: TweetQuery): Promise; /** * Fetches the most recent tweet from a Twitter user. * @param user The user whose latest tweet should be returned. * @param includeRetweets Whether or not to include retweets. Defaults to `false`. * @returns The {@link Tweet} object or `null`/`undefined` if it couldn't be fetched. */ getLatestTweet(user: string, includeRetweets?: boolean, max?: number): Promise; /** * Fetches a single tweet. * @param id The ID of the tweet to fetch. * @returns The {@link Tweet} object, or `null` if it couldn't be fetched. */ getTweet(id: string): Promise; /** * Returns if the scraper has a guest token. The token may not be valid. * @returns `true` if the scraper has a guest token; otherwise `false`. */ hasGuestToken(): boolean; /** * Returns if the scraper is logged in as a real user. * @returns `true` if the scraper is logged in with a real user account; otherwise `false`. */ isLoggedIn(): Promise; /** * Login to Twitter as a real Twitter account. This enables running * searches. * @param username The username of the Twitter account to login with. * @param password The password of the Twitter account to login with. * @param email The password to log in with, if you have email confirmation enabled. */ login(username: string, password: string, email?: string): Promise; /** * Log out of Twitter. */ logout(): Promise; /** * Retrieves all cookies for the current session. * @returns All cookies for the current session. */ getCookies(): Promise; /** * Set cookies for the current session. * @param cookies The cookies to set for the current session. */ setCookies(cookies: (string | Cookie)[]): Promise; /** * Clear all cookies for the current session. */ clearCookies(): Promise; /** * Sets the optional cookie to be used in requests. * @param _cookie The cookie to be used in requests. * @deprecated This function no longer represents any part of Twitter's auth flow. * @returns This scraper instance. */ withCookie(_cookie: string): Scraper; /** * Sets the optional CSRF token to be used in requests. * @param _token The CSRF token to be used in requests. * @deprecated This function no longer represents any part of Twitter's auth flow. * @returns This scraper instance. */ withXCsrfToken(_token: string): Scraper; private getAuthOptions; private handleResponse; } //# sourceMappingURL=scraper.d.ts.map