@the-convocation/twitter-scraper 0.20.0 → 0.20.2
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/default/cjs/index.js +45 -17
- package/dist/default/cjs/index.js.map +1 -1
- package/dist/default/esm/index.mjs +45 -17
- package/dist/default/esm/index.mjs.map +1 -1
- package/dist/node/cjs/index.cjs +45 -17
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.mjs +45 -17
- package/dist/node/esm/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -271,14 +271,17 @@ class TwitterGuestAuth {
|
|
|
271
271
|
}
|
|
272
272
|
return new Date(this.guestCreatedAt);
|
|
273
273
|
}
|
|
274
|
-
async installTo(headers) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
274
|
+
async installTo(headers, _url, bearerTokenOverride) {
|
|
275
|
+
const tokenToUse = bearerTokenOverride ?? this.bearerToken;
|
|
276
|
+
if (!bearerTokenOverride) {
|
|
277
|
+
if (this.shouldUpdate()) {
|
|
278
|
+
await this.updateGuestToken();
|
|
279
|
+
}
|
|
280
|
+
if (this.guestToken) {
|
|
281
|
+
headers.set("x-guest-token", this.guestToken);
|
|
282
|
+
}
|
|
280
283
|
}
|
|
281
|
-
headers.set("authorization", `Bearer ${
|
|
284
|
+
headers.set("authorization", `Bearer ${tokenToUse}`);
|
|
282
285
|
headers.set(
|
|
283
286
|
"user-agent",
|
|
284
287
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
|
|
@@ -518,13 +521,14 @@ async function generateTransactionId(url, fetchFn, method) {
|
|
|
518
521
|
|
|
519
522
|
const log$1 = debug("twitter-scraper:api");
|
|
520
523
|
const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
|
|
524
|
+
const bearerToken2 = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
|
|
521
525
|
async function jitter(maxMs) {
|
|
522
526
|
const jitter2 = Math.random() * maxMs;
|
|
523
527
|
await new Promise((resolve) => setTimeout(resolve, jitter2));
|
|
524
528
|
}
|
|
525
|
-
async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new headersPolyfill.Headers()) {
|
|
529
|
+
async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new headersPolyfill.Headers(), bearerTokenOverride) {
|
|
526
530
|
log$1(`Making ${method} request to ${url}`);
|
|
527
|
-
await auth.installTo(headers, url);
|
|
531
|
+
await auth.installTo(headers, url, bearerTokenOverride);
|
|
528
532
|
await platform.randomizeCiphers();
|
|
529
533
|
if (auth instanceof TwitterGuestAuth && auth.options?.experimental?.xClientTransactionId) {
|
|
530
534
|
const transactionId = await generateTransactionId(
|
|
@@ -765,8 +769,9 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
765
769
|
this.jar = new toughCookie.CookieJar();
|
|
766
770
|
}
|
|
767
771
|
}
|
|
768
|
-
async installTo(headers) {
|
|
769
|
-
|
|
772
|
+
async installTo(headers, _url, bearerTokenOverride) {
|
|
773
|
+
const tokenToUse = bearerTokenOverride ?? this.bearerToken;
|
|
774
|
+
headers.set("authorization", `Bearer ${tokenToUse}`);
|
|
770
775
|
headers.set(
|
|
771
776
|
"user-agent",
|
|
772
777
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
|
|
@@ -1008,7 +1013,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
1008
1013
|
"x-twitter-active-user": "yes",
|
|
1009
1014
|
"x-twitter-client-language": "en"
|
|
1010
1015
|
});
|
|
1011
|
-
await this.installTo(headers);
|
|
1016
|
+
await this.installTo(headers, onboardingTaskUrl);
|
|
1012
1017
|
if (this.options?.experimental?.xClientTransactionId) {
|
|
1013
1018
|
const transactionId = await generateTransactionId(
|
|
1014
1019
|
onboardingTaskUrl,
|
|
@@ -1185,7 +1190,14 @@ function parseProfile(legacy, isBlueVerified) {
|
|
|
1185
1190
|
async function getProfile(username, auth) {
|
|
1186
1191
|
const request = apiRequestFactory.createUserByScreenNameRequest();
|
|
1187
1192
|
request.variables.screen_name = username;
|
|
1188
|
-
const res = await requestApi(
|
|
1193
|
+
const res = await requestApi(
|
|
1194
|
+
request.toRequestUrl(),
|
|
1195
|
+
auth,
|
|
1196
|
+
"GET",
|
|
1197
|
+
void 0,
|
|
1198
|
+
void 0,
|
|
1199
|
+
bearerToken2
|
|
1200
|
+
);
|
|
1189
1201
|
if (!res.success) {
|
|
1190
1202
|
return res;
|
|
1191
1203
|
}
|
|
@@ -2039,7 +2051,11 @@ async function getTrends(auth) {
|
|
|
2039
2051
|
params.set("entity_tokens", "false");
|
|
2040
2052
|
const res = await requestApi(
|
|
2041
2053
|
`https://api.x.com/2/guide.json?${params.toString()}`,
|
|
2042
|
-
auth
|
|
2054
|
+
auth,
|
|
2055
|
+
"GET",
|
|
2056
|
+
void 0,
|
|
2057
|
+
void 0,
|
|
2058
|
+
bearerToken2
|
|
2043
2059
|
);
|
|
2044
2060
|
if (!res.success) {
|
|
2045
2061
|
throw res.err;
|
|
@@ -2122,7 +2138,11 @@ async function fetchTweets(userId, maxTweets, cursor, auth) {
|
|
|
2122
2138
|
}
|
|
2123
2139
|
const res = await requestApi(
|
|
2124
2140
|
userTweetsRequest.toRequestUrl(),
|
|
2125
|
-
auth
|
|
2141
|
+
auth,
|
|
2142
|
+
"GET",
|
|
2143
|
+
void 0,
|
|
2144
|
+
void 0,
|
|
2145
|
+
bearerToken2
|
|
2126
2146
|
);
|
|
2127
2147
|
if (!res.success) {
|
|
2128
2148
|
throw res.err;
|
|
@@ -2268,7 +2288,11 @@ async function getTweet(id, auth) {
|
|
|
2268
2288
|
tweetDetailRequest.variables.focalTweetId = id;
|
|
2269
2289
|
const res = await requestApi(
|
|
2270
2290
|
tweetDetailRequest.toRequestUrl(),
|
|
2271
|
-
auth
|
|
2291
|
+
auth,
|
|
2292
|
+
"GET",
|
|
2293
|
+
void 0,
|
|
2294
|
+
void 0,
|
|
2295
|
+
bearerToken2
|
|
2272
2296
|
);
|
|
2273
2297
|
if (!res.success) {
|
|
2274
2298
|
throw res.err;
|
|
@@ -2284,7 +2308,11 @@ async function getTweetAnonymous(id, auth) {
|
|
|
2284
2308
|
tweetResultByRestIdRequest.variables.tweetId = id;
|
|
2285
2309
|
const res = await requestApi(
|
|
2286
2310
|
tweetResultByRestIdRequest.toRequestUrl(),
|
|
2287
|
-
auth
|
|
2311
|
+
auth,
|
|
2312
|
+
"GET",
|
|
2313
|
+
void 0,
|
|
2314
|
+
void 0,
|
|
2315
|
+
bearerToken2
|
|
2288
2316
|
);
|
|
2289
2317
|
if (!res.success) {
|
|
2290
2318
|
throw res.err;
|