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