@the-convocation/twitter-scraper 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +76 -76
- package/dist/auth.js +118 -118
- package/dist/profile.js +102 -102
- package/dist/scraper.js +152 -152
- package/dist/search.js +83 -83
- package/dist/timeline-async.js +58 -58
- package/dist/timeline.js +227 -227
- package/dist/trends.js +45 -45
- package/dist/tweets.js +58 -58
- package/dist/types/api.d.ts +15 -15
- package/dist/types/auth.d.ts +54 -54
- package/dist/types/profile.d.ts +66 -66
- package/dist/types/scraper.d.ts +101 -101
- package/dist/types/search.d.ts +18 -18
- package/dist/types/timeline-async.d.ts +14 -14
- package/dist/types/timeline.d.ts +153 -153
- package/dist/types/trends.d.ts +2 -2
- package/dist/types/tweets.d.ts +51 -51
- package/package.json +1 -1
- package/.commitlintrc +0 -5
- package/.eslintcache +0 -1
- package/.eslintrc.js +0 -24
- package/.gitattributes +0 -78
- package/.prettierignore +0 -2
- package/.prettierrc +0 -5
package/dist/tweets.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { addApiParams, requestApi } from './api';
|
|
11
|
-
import { getUserIdByScreenName } from './profile';
|
|
12
|
-
import { parseTweets } from './timeline';
|
|
13
|
-
import { getTweetTimeline } from './timeline-async';
|
|
14
|
-
export function fetchTweets(user, maxTweets, includeReplies, cursor, auth) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
if (maxTweets > 200) {
|
|
17
|
-
maxTweets = 200;
|
|
18
|
-
}
|
|
19
|
-
const userIdRes = yield getUserIdByScreenName(user, auth);
|
|
20
|
-
if (!userIdRes.success) {
|
|
21
|
-
throw userIdRes.err;
|
|
22
|
-
}
|
|
23
|
-
const params = new URLSearchParams();
|
|
24
|
-
addApiParams(params, includeReplies);
|
|
25
|
-
params.set('count', `${maxTweets}`);
|
|
26
|
-
params.set('userId', userIdRes.value);
|
|
27
|
-
if (cursor != null && cursor != '') {
|
|
28
|
-
params.set('cursor', cursor);
|
|
29
|
-
}
|
|
30
|
-
const res = yield requestApi(`https://api.twitter.com/2/timeline/profile/${userIdRes.value}.json?${params.toString()}`, auth);
|
|
31
|
-
if (!res.success) {
|
|
32
|
-
throw res.err;
|
|
33
|
-
}
|
|
34
|
-
return parseTweets(res.value);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export function getTweets(user, maxTweets, includeReplies, auth) {
|
|
38
|
-
return getTweetTimeline(user, maxTweets, (q, mt, c) => {
|
|
39
|
-
return fetchTweets(q, mt, includeReplies, c, auth);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
export function getTweet(id, includeReplies, auth) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const params = new URLSearchParams();
|
|
45
|
-
addApiParams(params, includeReplies);
|
|
46
|
-
const res = yield requestApi(`https://twitter.com/i/api/2/timeline/conversation/${id}.json?${params.toString()}`, auth);
|
|
47
|
-
if (!res.success) {
|
|
48
|
-
throw res.err;
|
|
49
|
-
}
|
|
50
|
-
const { tweets } = parseTweets(res.value);
|
|
51
|
-
for (const tweet of tweets) {
|
|
52
|
-
if (tweet.id === id) {
|
|
53
|
-
return tweet;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { addApiParams, requestApi } from './api';
|
|
11
|
+
import { getUserIdByScreenName } from './profile';
|
|
12
|
+
import { parseTweets } from './timeline';
|
|
13
|
+
import { getTweetTimeline } from './timeline-async';
|
|
14
|
+
export function fetchTweets(user, maxTweets, includeReplies, cursor, auth) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
if (maxTweets > 200) {
|
|
17
|
+
maxTweets = 200;
|
|
18
|
+
}
|
|
19
|
+
const userIdRes = yield getUserIdByScreenName(user, auth);
|
|
20
|
+
if (!userIdRes.success) {
|
|
21
|
+
throw userIdRes.err;
|
|
22
|
+
}
|
|
23
|
+
const params = new URLSearchParams();
|
|
24
|
+
addApiParams(params, includeReplies);
|
|
25
|
+
params.set('count', `${maxTweets}`);
|
|
26
|
+
params.set('userId', userIdRes.value);
|
|
27
|
+
if (cursor != null && cursor != '') {
|
|
28
|
+
params.set('cursor', cursor);
|
|
29
|
+
}
|
|
30
|
+
const res = yield requestApi(`https://api.twitter.com/2/timeline/profile/${userIdRes.value}.json?${params.toString()}`, auth);
|
|
31
|
+
if (!res.success) {
|
|
32
|
+
throw res.err;
|
|
33
|
+
}
|
|
34
|
+
return parseTweets(res.value);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function getTweets(user, maxTweets, includeReplies, auth) {
|
|
38
|
+
return getTweetTimeline(user, maxTweets, (q, mt, c) => {
|
|
39
|
+
return fetchTweets(q, mt, includeReplies, c, auth);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export function getTweet(id, includeReplies, auth) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const params = new URLSearchParams();
|
|
45
|
+
addApiParams(params, includeReplies);
|
|
46
|
+
const res = yield requestApi(`https://twitter.com/i/api/2/timeline/conversation/${id}.json?${params.toString()}`, auth);
|
|
47
|
+
if (!res.success) {
|
|
48
|
+
throw res.err;
|
|
49
|
+
}
|
|
50
|
+
const { tweets } = parseTweets(res.value);
|
|
51
|
+
for (const tweet of tweets) {
|
|
52
|
+
if (tweet.id === id) {
|
|
53
|
+
return tweet;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
59
|
//# sourceMappingURL=tweets.js.map
|
package/dist/types/api.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { TwitterGuestAuth } from './auth';
|
|
2
|
-
export declare const bearerToken = "AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw";
|
|
3
|
-
export declare const bearerToken2 = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
|
|
4
|
-
/**
|
|
5
|
-
* An API result container.
|
|
6
|
-
*/
|
|
7
|
-
export declare type RequestApiResult<T> = {
|
|
8
|
-
success: true;
|
|
9
|
-
value: T;
|
|
10
|
-
} | {
|
|
11
|
-
success: false;
|
|
12
|
-
err: Error;
|
|
13
|
-
};
|
|
14
|
-
export declare function requestApi<T>(url: string, auth: TwitterGuestAuth): Promise<RequestApiResult<T>>;
|
|
15
|
-
export declare function addApiParams(params: URLSearchParams, includeTweetReplies: boolean): URLSearchParams;
|
|
1
|
+
import { TwitterGuestAuth } from './auth';
|
|
2
|
+
export declare const bearerToken = "AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw";
|
|
3
|
+
export declare const bearerToken2 = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
|
|
4
|
+
/**
|
|
5
|
+
* An API result container.
|
|
6
|
+
*/
|
|
7
|
+
export declare type RequestApiResult<T> = {
|
|
8
|
+
success: true;
|
|
9
|
+
value: T;
|
|
10
|
+
} | {
|
|
11
|
+
success: false;
|
|
12
|
+
err: Error;
|
|
13
|
+
};
|
|
14
|
+
export declare function requestApi<T>(url: string, auth: TwitterGuestAuth): Promise<RequestApiResult<T>>;
|
|
15
|
+
export declare function addApiParams(params: URLSearchParams, includeTweetReplies: boolean): URLSearchParams;
|
|
16
16
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A guest authentication token manager. Automatically handles token refreshes.
|
|
3
|
-
*/
|
|
4
|
-
export declare class TwitterGuestAuth {
|
|
5
|
-
private bearerToken;
|
|
6
|
-
private cookie?;
|
|
7
|
-
private guestToken?;
|
|
8
|
-
private guestCreatedAt?;
|
|
9
|
-
private xCsrfToken?;
|
|
10
|
-
constructor(bearerToken: string, cookie?: string, xCsrfToken?: string);
|
|
11
|
-
/**
|
|
12
|
-
* Deletes the authentication token.
|
|
13
|
-
*/
|
|
14
|
-
deleteToken(): void;
|
|
15
|
-
/**
|
|
16
|
-
* Returns if the authentication state has a token.
|
|
17
|
-
* @returns `true` if the authentication state has a token; `false` otherwise.
|
|
18
|
-
*/
|
|
19
|
-
hasToken(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Returns the time that authentication was performed.
|
|
22
|
-
* @returns The time at which the authentication token was created, or `null` if it hasn't been created yet.
|
|
23
|
-
*/
|
|
24
|
-
authenticatedAt(): Date | null;
|
|
25
|
-
/**
|
|
26
|
-
* Sets a cookie string for use in requests.
|
|
27
|
-
* @param value The new cookie to use in requests.
|
|
28
|
-
*/
|
|
29
|
-
useCookie(value: string): void;
|
|
30
|
-
/**
|
|
31
|
-
* Sets a new CSRF token for use in requests.
|
|
32
|
-
* @param value The new CSRF token to use in requests.
|
|
33
|
-
*/
|
|
34
|
-
useCsrfToken(value: string): void;
|
|
35
|
-
/**
|
|
36
|
-
* Installs the authentication information into a headers-like object. If needed, the
|
|
37
|
-
* authentication token will be updated from the API automatically.
|
|
38
|
-
* @param headers A key-value object representing a request's headers.
|
|
39
|
-
* @returns A builder that can be used to add or override other relevant data, or to
|
|
40
|
-
* complete the task.
|
|
41
|
-
*/
|
|
42
|
-
installTo(headers: {
|
|
43
|
-
[key: string]: unknown;
|
|
44
|
-
}): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Updates the authentication state with a new guest token from the Twitter API.
|
|
47
|
-
*/
|
|
48
|
-
updateToken(): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Returns if the authentication token needs to be updated or not.
|
|
51
|
-
* @returns `true` if the token needs to be updated; `false` otherwise.
|
|
52
|
-
*/
|
|
53
|
-
private shouldUpdate;
|
|
54
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A guest authentication token manager. Automatically handles token refreshes.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TwitterGuestAuth {
|
|
5
|
+
private bearerToken;
|
|
6
|
+
private cookie?;
|
|
7
|
+
private guestToken?;
|
|
8
|
+
private guestCreatedAt?;
|
|
9
|
+
private xCsrfToken?;
|
|
10
|
+
constructor(bearerToken: string, cookie?: string, xCsrfToken?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Deletes the authentication token.
|
|
13
|
+
*/
|
|
14
|
+
deleteToken(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Returns if the authentication state has a token.
|
|
17
|
+
* @returns `true` if the authentication state has a token; `false` otherwise.
|
|
18
|
+
*/
|
|
19
|
+
hasToken(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the time that authentication was performed.
|
|
22
|
+
* @returns The time at which the authentication token was created, or `null` if it hasn't been created yet.
|
|
23
|
+
*/
|
|
24
|
+
authenticatedAt(): Date | null;
|
|
25
|
+
/**
|
|
26
|
+
* Sets a cookie string for use in requests.
|
|
27
|
+
* @param value The new cookie to use in requests.
|
|
28
|
+
*/
|
|
29
|
+
useCookie(value: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Sets a new CSRF token for use in requests.
|
|
32
|
+
* @param value The new CSRF token to use in requests.
|
|
33
|
+
*/
|
|
34
|
+
useCsrfToken(value: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Installs the authentication information into a headers-like object. If needed, the
|
|
37
|
+
* authentication token will be updated from the API automatically.
|
|
38
|
+
* @param headers A key-value object representing a request's headers.
|
|
39
|
+
* @returns A builder that can be used to add or override other relevant data, or to
|
|
40
|
+
* complete the task.
|
|
41
|
+
*/
|
|
42
|
+
installTo(headers: {
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Updates the authentication state with a new guest token from the Twitter API.
|
|
47
|
+
*/
|
|
48
|
+
updateToken(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns if the authentication token needs to be updated or not.
|
|
51
|
+
* @returns `true` if the token needs to be updated; `false` otherwise.
|
|
52
|
+
*/
|
|
53
|
+
private shouldUpdate;
|
|
54
|
+
}
|
|
55
55
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/types/profile.d.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { RequestApiResult } from './api';
|
|
2
|
-
import { TwitterGuestAuth } from './auth';
|
|
3
|
-
export interface LegacyUserRaw {
|
|
4
|
-
created_at?: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
entities?: {
|
|
7
|
-
url?: {
|
|
8
|
-
urls?: {
|
|
9
|
-
expanded_url?: string;
|
|
10
|
-
}[];
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
favourites_count?: number;
|
|
14
|
-
followers_count?: number;
|
|
15
|
-
friends_count?: number;
|
|
16
|
-
id_str?: string;
|
|
17
|
-
listed_count?: number;
|
|
18
|
-
name?: string;
|
|
19
|
-
location: string;
|
|
20
|
-
pinned_tweet_ids_str?: string[];
|
|
21
|
-
profile_banner_url?: string;
|
|
22
|
-
profile_image_url_https?: string;
|
|
23
|
-
protected?: boolean;
|
|
24
|
-
screen_name?: string;
|
|
25
|
-
statuses_count?: number;
|
|
26
|
-
verified?: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A parsed profile object.
|
|
30
|
-
*/
|
|
31
|
-
export interface Profile {
|
|
32
|
-
avatar?: string;
|
|
33
|
-
banner?: string;
|
|
34
|
-
biography?: string;
|
|
35
|
-
birthday?: string;
|
|
36
|
-
followersCount?: number;
|
|
37
|
-
followingCount?: number;
|
|
38
|
-
friendsCount?: number;
|
|
39
|
-
isPrivate?: boolean;
|
|
40
|
-
isVerified?: boolean;
|
|
41
|
-
joined?: Date;
|
|
42
|
-
likesCount?: number;
|
|
43
|
-
listedCount?: number;
|
|
44
|
-
location: string;
|
|
45
|
-
name?: string;
|
|
46
|
-
pinnedTweetIds?: string[];
|
|
47
|
-
tweetsCount?: number;
|
|
48
|
-
url?: string;
|
|
49
|
-
userId?: string;
|
|
50
|
-
username?: string;
|
|
51
|
-
website?: string;
|
|
52
|
-
}
|
|
53
|
-
export interface UserRaw {
|
|
54
|
-
data: {
|
|
55
|
-
user: {
|
|
56
|
-
rest_id?: string;
|
|
57
|
-
legacy: LegacyUserRaw;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
errors?: {
|
|
61
|
-
message: string;
|
|
62
|
-
}[];
|
|
63
|
-
}
|
|
64
|
-
export declare function parseProfile(user: LegacyUserRaw): Profile;
|
|
65
|
-
export declare function getProfile(username: string, auth: TwitterGuestAuth): Promise<RequestApiResult<Profile>>;
|
|
66
|
-
export declare function getUserIdByScreenName(screenName: string, auth: TwitterGuestAuth): Promise<RequestApiResult<string>>;
|
|
1
|
+
import { RequestApiResult } from './api';
|
|
2
|
+
import { TwitterGuestAuth } from './auth';
|
|
3
|
+
export interface LegacyUserRaw {
|
|
4
|
+
created_at?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
entities?: {
|
|
7
|
+
url?: {
|
|
8
|
+
urls?: {
|
|
9
|
+
expanded_url?: string;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
favourites_count?: number;
|
|
14
|
+
followers_count?: number;
|
|
15
|
+
friends_count?: number;
|
|
16
|
+
id_str?: string;
|
|
17
|
+
listed_count?: number;
|
|
18
|
+
name?: string;
|
|
19
|
+
location: string;
|
|
20
|
+
pinned_tweet_ids_str?: string[];
|
|
21
|
+
profile_banner_url?: string;
|
|
22
|
+
profile_image_url_https?: string;
|
|
23
|
+
protected?: boolean;
|
|
24
|
+
screen_name?: string;
|
|
25
|
+
statuses_count?: number;
|
|
26
|
+
verified?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A parsed profile object.
|
|
30
|
+
*/
|
|
31
|
+
export interface Profile {
|
|
32
|
+
avatar?: string;
|
|
33
|
+
banner?: string;
|
|
34
|
+
biography?: string;
|
|
35
|
+
birthday?: string;
|
|
36
|
+
followersCount?: number;
|
|
37
|
+
followingCount?: number;
|
|
38
|
+
friendsCount?: number;
|
|
39
|
+
isPrivate?: boolean;
|
|
40
|
+
isVerified?: boolean;
|
|
41
|
+
joined?: Date;
|
|
42
|
+
likesCount?: number;
|
|
43
|
+
listedCount?: number;
|
|
44
|
+
location: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
pinnedTweetIds?: string[];
|
|
47
|
+
tweetsCount?: number;
|
|
48
|
+
url?: string;
|
|
49
|
+
userId?: string;
|
|
50
|
+
username?: string;
|
|
51
|
+
website?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface UserRaw {
|
|
54
|
+
data: {
|
|
55
|
+
user: {
|
|
56
|
+
rest_id?: string;
|
|
57
|
+
legacy: LegacyUserRaw;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
errors?: {
|
|
61
|
+
message: string;
|
|
62
|
+
}[];
|
|
63
|
+
}
|
|
64
|
+
export declare function parseProfile(user: LegacyUserRaw): Profile;
|
|
65
|
+
export declare function getProfile(username: string, auth: TwitterGuestAuth): Promise<RequestApiResult<Profile>>;
|
|
66
|
+
export declare function getUserIdByScreenName(screenName: string, auth: TwitterGuestAuth): Promise<RequestApiResult<string>>;
|
|
67
67
|
//# sourceMappingURL=profile.d.ts.map
|
package/dist/types/scraper.d.ts
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { Profile } from './profile';
|
|
2
|
-
import { SearchMode } from './search';
|
|
3
|
-
import { QueryProfilesResponse, QueryTweetsResponse } from './timeline';
|
|
4
|
-
import { Tweet } from './tweets';
|
|
5
|
-
/**
|
|
6
|
-
* An interface to Twitter's undocumented API.
|
|
7
|
-
* Reusing Scraper objects is recommended to minimize the time spent authenticating unnecessarily.
|
|
8
|
-
*/
|
|
9
|
-
export declare class Scraper {
|
|
10
|
-
private auth;
|
|
11
|
-
private authTrends;
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new Scraper object. Scrapers maintain their own guest tokens for Twitter's internal API.
|
|
14
|
-
* Reusing Scraper objects is recommended to minimize the time spent authenticating unnecessarily.
|
|
15
|
-
*/
|
|
16
|
-
constructor();
|
|
17
|
-
/**
|
|
18
|
-
* Fetches a Twitter profile.
|
|
19
|
-
* @param username The Twitter username of the profile to fetch, without an `@` at the beginning.
|
|
20
|
-
* @returns The requested profile.
|
|
21
|
-
*/
|
|
22
|
-
getProfile(username: string): Promise<Profile>;
|
|
23
|
-
/**
|
|
24
|
-
* Fetches the user ID corresponding to the provided screen name.
|
|
25
|
-
* @param screenName The Twitter screen name of the profile to fetch.
|
|
26
|
-
* @returns The ID of the corresponding account.
|
|
27
|
-
*/
|
|
28
|
-
getUserIdByScreenName(screenName: string): Promise<string>;
|
|
29
|
-
/**
|
|
30
|
-
* Fetches tweets from Twitter.
|
|
31
|
-
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
32
|
-
* @param maxTweets The maximum number of tweets to return.
|
|
33
|
-
* @param includeReplies Whether or not replies should be included in the response.
|
|
34
|
-
* @param searchMode The category filter to apply to the search. Defaults to `Top`.
|
|
35
|
-
* @returns An async generator of tweets matching the provided filters.
|
|
36
|
-
*/
|
|
37
|
-
searchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode?: SearchMode): AsyncGenerator<Tweet>;
|
|
38
|
-
/**
|
|
39
|
-
* Fetches profiles from Twitter.
|
|
40
|
-
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
41
|
-
* @param maxProfiles The maximum number of profiles to return.
|
|
42
|
-
* @returns An async generator of tweets matching the provided filters.
|
|
43
|
-
*/
|
|
44
|
-
searchProfiles(query: string, maxProfiles: number): AsyncGenerator<Profile>;
|
|
45
|
-
/**
|
|
46
|
-
* Fetches tweets from Twitter.
|
|
47
|
-
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
48
|
-
* @param maxTweets The maximum number of tweets to return.
|
|
49
|
-
* @param includeReplies Whether or not replies should be included in the response.
|
|
50
|
-
* @param searchMode The category filter to apply to the search. Defaults to `Top`.
|
|
51
|
-
* @param cursor The search cursor, which can be passed into further requests for more results.
|
|
52
|
-
* @returns A page of results, containing a cursor that can be used in further requests.
|
|
53
|
-
*/
|
|
54
|
-
fetchSearchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode: SearchMode, cursor?: string): Promise<QueryTweetsResponse>;
|
|
55
|
-
/**
|
|
56
|
-
* Fetches profiles from Twitter.
|
|
57
|
-
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
58
|
-
* @param maxProfiles The maximum number of profiles to return.
|
|
59
|
-
* @param cursor The search cursor, which can be passed into further requests for more results.
|
|
60
|
-
* @returns A page of results, containing a cursor that can be used in further requests.
|
|
61
|
-
*/
|
|
62
|
-
fetchSearchProfiles(query: string, maxProfiles: number, cursor?: string): Promise<QueryProfilesResponse>;
|
|
63
|
-
/**
|
|
64
|
-
* Fetches the current trends from Twitter.
|
|
65
|
-
* @returns The current list of trends.
|
|
66
|
-
*/
|
|
67
|
-
getTrends(): Promise<string[]>;
|
|
68
|
-
/**
|
|
69
|
-
* Fetches tweets from a Twitter user.
|
|
70
|
-
* @param user The user whose tweets should be returned.
|
|
71
|
-
* @param maxTweets The maximum number of tweets to return.
|
|
72
|
-
* @param includeReplies Whether or not to include tweet replies.
|
|
73
|
-
* @returns An async generator of tweets from the provided user.
|
|
74
|
-
*/
|
|
75
|
-
getTweets(user: string, maxTweets: number, includeReplies: boolean): AsyncGenerator<Tweet>;
|
|
76
|
-
/**
|
|
77
|
-
* Fetches a single tweet.
|
|
78
|
-
* @param id The ID of the tweet to fetch.
|
|
79
|
-
* @param includeReplies Whether or not to include tweet replies.
|
|
80
|
-
* @returns The request tweet, or `null` if it couldn't be fetched.
|
|
81
|
-
*/
|
|
82
|
-
getTweet(id: string, includeReplies: boolean): Promise<Tweet | null>;
|
|
83
|
-
/**
|
|
84
|
-
* Returns if the scraper has a guest token. The token may not be valid.
|
|
85
|
-
* @returns `true` if the scraper has a guest token; otherwise `false`.
|
|
86
|
-
*/
|
|
87
|
-
hasGuestToken(): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Sets the optional cookie to be used in requests.
|
|
90
|
-
* @param cookie The cookie to be used in requests.
|
|
91
|
-
* @returns This scraper instance.
|
|
92
|
-
*/
|
|
93
|
-
withCookie(cookie: string): Scraper;
|
|
94
|
-
/**
|
|
95
|
-
* Sets the optional CSRF token to be used in requests.
|
|
96
|
-
* @param token The CSRF token to be used in requests.
|
|
97
|
-
* @returns This scraper instance.
|
|
98
|
-
*/
|
|
99
|
-
withXCsrfToken(token: string): Scraper;
|
|
100
|
-
private handleResponse;
|
|
101
|
-
}
|
|
1
|
+
import { Profile } from './profile';
|
|
2
|
+
import { SearchMode } from './search';
|
|
3
|
+
import { QueryProfilesResponse, QueryTweetsResponse } from './timeline';
|
|
4
|
+
import { Tweet } from './tweets';
|
|
5
|
+
/**
|
|
6
|
+
* An interface to Twitter's undocumented API.
|
|
7
|
+
* Reusing Scraper objects is recommended to minimize the time spent authenticating unnecessarily.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Scraper {
|
|
10
|
+
private auth;
|
|
11
|
+
private authTrends;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new Scraper object. Scrapers maintain their own guest tokens for Twitter's internal API.
|
|
14
|
+
* Reusing Scraper objects is recommended to minimize the time spent authenticating unnecessarily.
|
|
15
|
+
*/
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Fetches a Twitter profile.
|
|
19
|
+
* @param username The Twitter username of the profile to fetch, without an `@` at the beginning.
|
|
20
|
+
* @returns The requested profile.
|
|
21
|
+
*/
|
|
22
|
+
getProfile(username: string): Promise<Profile>;
|
|
23
|
+
/**
|
|
24
|
+
* Fetches the user ID corresponding to the provided screen name.
|
|
25
|
+
* @param screenName The Twitter screen name of the profile to fetch.
|
|
26
|
+
* @returns The ID of the corresponding account.
|
|
27
|
+
*/
|
|
28
|
+
getUserIdByScreenName(screenName: string): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Fetches tweets from Twitter.
|
|
31
|
+
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
32
|
+
* @param maxTweets The maximum number of tweets to return.
|
|
33
|
+
* @param includeReplies Whether or not replies should be included in the response.
|
|
34
|
+
* @param searchMode The category filter to apply to the search. Defaults to `Top`.
|
|
35
|
+
* @returns An async generator of tweets matching the provided filters.
|
|
36
|
+
*/
|
|
37
|
+
searchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode?: SearchMode): AsyncGenerator<Tweet>;
|
|
38
|
+
/**
|
|
39
|
+
* Fetches profiles from Twitter.
|
|
40
|
+
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
41
|
+
* @param maxProfiles The maximum number of profiles to return.
|
|
42
|
+
* @returns An async generator of tweets matching the provided filters.
|
|
43
|
+
*/
|
|
44
|
+
searchProfiles(query: string, maxProfiles: number): AsyncGenerator<Profile>;
|
|
45
|
+
/**
|
|
46
|
+
* Fetches tweets from Twitter.
|
|
47
|
+
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
48
|
+
* @param maxTweets The maximum number of tweets to return.
|
|
49
|
+
* @param includeReplies Whether or not replies should be included in the response.
|
|
50
|
+
* @param searchMode The category filter to apply to the search. Defaults to `Top`.
|
|
51
|
+
* @param cursor The search cursor, which can be passed into further requests for more results.
|
|
52
|
+
* @returns A page of results, containing a cursor that can be used in further requests.
|
|
53
|
+
*/
|
|
54
|
+
fetchSearchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode: SearchMode, cursor?: string): Promise<QueryTweetsResponse>;
|
|
55
|
+
/**
|
|
56
|
+
* Fetches profiles from Twitter.
|
|
57
|
+
* @param query The search query. Any Twitter-compatible query format can be used.
|
|
58
|
+
* @param maxProfiles The maximum number of profiles to return.
|
|
59
|
+
* @param cursor The search cursor, which can be passed into further requests for more results.
|
|
60
|
+
* @returns A page of results, containing a cursor that can be used in further requests.
|
|
61
|
+
*/
|
|
62
|
+
fetchSearchProfiles(query: string, maxProfiles: number, cursor?: string): Promise<QueryProfilesResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Fetches the current trends from Twitter.
|
|
65
|
+
* @returns The current list of trends.
|
|
66
|
+
*/
|
|
67
|
+
getTrends(): Promise<string[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Fetches tweets from a Twitter user.
|
|
70
|
+
* @param user The user whose tweets should be returned.
|
|
71
|
+
* @param maxTweets The maximum number of tweets to return.
|
|
72
|
+
* @param includeReplies Whether or not to include tweet replies.
|
|
73
|
+
* @returns An async generator of tweets from the provided user.
|
|
74
|
+
*/
|
|
75
|
+
getTweets(user: string, maxTweets: number, includeReplies: boolean): AsyncGenerator<Tweet>;
|
|
76
|
+
/**
|
|
77
|
+
* Fetches a single tweet.
|
|
78
|
+
* @param id The ID of the tweet to fetch.
|
|
79
|
+
* @param includeReplies Whether or not to include tweet replies.
|
|
80
|
+
* @returns The request tweet, or `null` if it couldn't be fetched.
|
|
81
|
+
*/
|
|
82
|
+
getTweet(id: string, includeReplies: boolean): Promise<Tweet | null>;
|
|
83
|
+
/**
|
|
84
|
+
* Returns if the scraper has a guest token. The token may not be valid.
|
|
85
|
+
* @returns `true` if the scraper has a guest token; otherwise `false`.
|
|
86
|
+
*/
|
|
87
|
+
hasGuestToken(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Sets the optional cookie to be used in requests.
|
|
90
|
+
* @param cookie The cookie to be used in requests.
|
|
91
|
+
* @returns This scraper instance.
|
|
92
|
+
*/
|
|
93
|
+
withCookie(cookie: string): Scraper;
|
|
94
|
+
/**
|
|
95
|
+
* Sets the optional CSRF token to be used in requests.
|
|
96
|
+
* @param token The CSRF token to be used in requests.
|
|
97
|
+
* @returns This scraper instance.
|
|
98
|
+
*/
|
|
99
|
+
withXCsrfToken(token: string): Scraper;
|
|
100
|
+
private handleResponse;
|
|
101
|
+
}
|
|
102
102
|
//# sourceMappingURL=scraper.d.ts.map
|
package/dist/types/search.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { TwitterGuestAuth } from './auth';
|
|
2
|
-
import { Profile } from './profile';
|
|
3
|
-
import { QueryProfilesResponse, QueryTweetsResponse } from './timeline';
|
|
4
|
-
import { Tweet } from './tweets';
|
|
5
|
-
/**
|
|
6
|
-
* The categories that can be used in Twitter searches.
|
|
7
|
-
*/
|
|
8
|
-
export declare enum SearchMode {
|
|
9
|
-
Top = 0,
|
|
10
|
-
Latest = 1,
|
|
11
|
-
Photos = 2,
|
|
12
|
-
Videos = 3,
|
|
13
|
-
Users = 4
|
|
14
|
-
}
|
|
15
|
-
export declare function searchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode: SearchMode, auth: TwitterGuestAuth): AsyncGenerator<Tweet>;
|
|
16
|
-
export declare function searchProfiles(query: string, maxProfiles: number, auth: TwitterGuestAuth): AsyncGenerator<Profile>;
|
|
17
|
-
export declare function fetchSearchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode: SearchMode, auth: TwitterGuestAuth, cursor?: string): Promise<QueryTweetsResponse>;
|
|
18
|
-
export declare function fetchSearchProfiles(query: string, maxProfiles: number, auth: TwitterGuestAuth, cursor?: string): Promise<QueryProfilesResponse>;
|
|
1
|
+
import { TwitterGuestAuth } from './auth';
|
|
2
|
+
import { Profile } from './profile';
|
|
3
|
+
import { QueryProfilesResponse, QueryTweetsResponse } from './timeline';
|
|
4
|
+
import { Tweet } from './tweets';
|
|
5
|
+
/**
|
|
6
|
+
* The categories that can be used in Twitter searches.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum SearchMode {
|
|
9
|
+
Top = 0,
|
|
10
|
+
Latest = 1,
|
|
11
|
+
Photos = 2,
|
|
12
|
+
Videos = 3,
|
|
13
|
+
Users = 4
|
|
14
|
+
}
|
|
15
|
+
export declare function searchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode: SearchMode, auth: TwitterGuestAuth): AsyncGenerator<Tweet>;
|
|
16
|
+
export declare function searchProfiles(query: string, maxProfiles: number, auth: TwitterGuestAuth): AsyncGenerator<Profile>;
|
|
17
|
+
export declare function fetchSearchTweets(query: string, maxTweets: number, includeReplies: boolean, searchMode: SearchMode, auth: TwitterGuestAuth, cursor?: string): Promise<QueryTweetsResponse>;
|
|
18
|
+
export declare function fetchSearchProfiles(query: string, maxProfiles: number, auth: TwitterGuestAuth, cursor?: string): Promise<QueryProfilesResponse>;
|
|
19
19
|
//# sourceMappingURL=search.d.ts.map
|