@the-convocation/twitter-scraper 0.20.0 → 0.20.1
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 +37 -16
- package/dist/default/cjs/index.js.map +1 -1
- package/dist/default/esm/index.mjs +37 -16
- package/dist/default/esm/index.mjs.map +1 -1
- package/dist/node/cjs/index.cjs +37 -16
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.mjs +37 -16
- 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,
|
|
@@ -2039,7 +2044,11 @@ async function getTrends(auth) {
|
|
|
2039
2044
|
params.set("entity_tokens", "false");
|
|
2040
2045
|
const res = await requestApi(
|
|
2041
2046
|
`https://api.x.com/2/guide.json?${params.toString()}`,
|
|
2042
|
-
auth
|
|
2047
|
+
auth,
|
|
2048
|
+
"GET",
|
|
2049
|
+
void 0,
|
|
2050
|
+
void 0,
|
|
2051
|
+
bearerToken2
|
|
2043
2052
|
);
|
|
2044
2053
|
if (!res.success) {
|
|
2045
2054
|
throw res.err;
|
|
@@ -2122,7 +2131,11 @@ async function fetchTweets(userId, maxTweets, cursor, auth) {
|
|
|
2122
2131
|
}
|
|
2123
2132
|
const res = await requestApi(
|
|
2124
2133
|
userTweetsRequest.toRequestUrl(),
|
|
2125
|
-
auth
|
|
2134
|
+
auth,
|
|
2135
|
+
"GET",
|
|
2136
|
+
void 0,
|
|
2137
|
+
void 0,
|
|
2138
|
+
bearerToken2
|
|
2126
2139
|
);
|
|
2127
2140
|
if (!res.success) {
|
|
2128
2141
|
throw res.err;
|
|
@@ -2268,7 +2281,11 @@ async function getTweet(id, auth) {
|
|
|
2268
2281
|
tweetDetailRequest.variables.focalTweetId = id;
|
|
2269
2282
|
const res = await requestApi(
|
|
2270
2283
|
tweetDetailRequest.toRequestUrl(),
|
|
2271
|
-
auth
|
|
2284
|
+
auth,
|
|
2285
|
+
"GET",
|
|
2286
|
+
void 0,
|
|
2287
|
+
void 0,
|
|
2288
|
+
bearerToken2
|
|
2272
2289
|
);
|
|
2273
2290
|
if (!res.success) {
|
|
2274
2291
|
throw res.err;
|
|
@@ -2284,7 +2301,11 @@ async function getTweetAnonymous(id, auth) {
|
|
|
2284
2301
|
tweetResultByRestIdRequest.variables.tweetId = id;
|
|
2285
2302
|
const res = await requestApi(
|
|
2286
2303
|
tweetResultByRestIdRequest.toRequestUrl(),
|
|
2287
|
-
auth
|
|
2304
|
+
auth,
|
|
2305
|
+
"GET",
|
|
2306
|
+
void 0,
|
|
2307
|
+
void 0,
|
|
2308
|
+
bearerToken2
|
|
2288
2309
|
);
|
|
2289
2310
|
if (!res.success) {
|
|
2290
2311
|
throw res.err;
|