@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
|
@@ -250,14 +250,17 @@ class TwitterGuestAuth {
|
|
|
250
250
|
}
|
|
251
251
|
return new Date(this.guestCreatedAt);
|
|
252
252
|
}
|
|
253
|
-
async installTo(headers) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
253
|
+
async installTo(headers, _url, bearerTokenOverride) {
|
|
254
|
+
const tokenToUse = bearerTokenOverride ?? this.bearerToken;
|
|
255
|
+
if (!bearerTokenOverride) {
|
|
256
|
+
if (this.shouldUpdate()) {
|
|
257
|
+
await this.updateGuestToken();
|
|
258
|
+
}
|
|
259
|
+
if (this.guestToken) {
|
|
260
|
+
headers.set("x-guest-token", this.guestToken);
|
|
261
|
+
}
|
|
259
262
|
}
|
|
260
|
-
headers.set("authorization", `Bearer ${
|
|
263
|
+
headers.set("authorization", `Bearer ${tokenToUse}`);
|
|
261
264
|
headers.set(
|
|
262
265
|
"user-agent",
|
|
263
266
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
|
|
@@ -497,13 +500,14 @@ async function generateTransactionId(url, fetchFn, method) {
|
|
|
497
500
|
|
|
498
501
|
const log$1 = debug("twitter-scraper:api");
|
|
499
502
|
const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
|
|
503
|
+
const bearerToken2 = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
|
|
500
504
|
async function jitter(maxMs) {
|
|
501
505
|
const jitter2 = Math.random() * maxMs;
|
|
502
506
|
await new Promise((resolve) => setTimeout(resolve, jitter2));
|
|
503
507
|
}
|
|
504
|
-
async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new Headers()) {
|
|
508
|
+
async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new Headers(), bearerTokenOverride) {
|
|
505
509
|
log$1(`Making ${method} request to ${url}`);
|
|
506
|
-
await auth.installTo(headers, url);
|
|
510
|
+
await auth.installTo(headers, url, bearerTokenOverride);
|
|
507
511
|
await platform.randomizeCiphers();
|
|
508
512
|
if (auth instanceof TwitterGuestAuth && auth.options?.experimental?.xClientTransactionId) {
|
|
509
513
|
const transactionId = await generateTransactionId(
|
|
@@ -744,8 +748,9 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
744
748
|
this.jar = new CookieJar();
|
|
745
749
|
}
|
|
746
750
|
}
|
|
747
|
-
async installTo(headers) {
|
|
748
|
-
|
|
751
|
+
async installTo(headers, _url, bearerTokenOverride) {
|
|
752
|
+
const tokenToUse = bearerTokenOverride ?? this.bearerToken;
|
|
753
|
+
headers.set("authorization", `Bearer ${tokenToUse}`);
|
|
749
754
|
headers.set(
|
|
750
755
|
"user-agent",
|
|
751
756
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
|
|
@@ -987,7 +992,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
987
992
|
"x-twitter-active-user": "yes",
|
|
988
993
|
"x-twitter-client-language": "en"
|
|
989
994
|
});
|
|
990
|
-
await this.installTo(headers);
|
|
995
|
+
await this.installTo(headers, onboardingTaskUrl);
|
|
991
996
|
if (this.options?.experimental?.xClientTransactionId) {
|
|
992
997
|
const transactionId = await generateTransactionId(
|
|
993
998
|
onboardingTaskUrl,
|
|
@@ -2018,7 +2023,11 @@ async function getTrends(auth) {
|
|
|
2018
2023
|
params.set("entity_tokens", "false");
|
|
2019
2024
|
const res = await requestApi(
|
|
2020
2025
|
`https://api.x.com/2/guide.json?${params.toString()}`,
|
|
2021
|
-
auth
|
|
2026
|
+
auth,
|
|
2027
|
+
"GET",
|
|
2028
|
+
void 0,
|
|
2029
|
+
void 0,
|
|
2030
|
+
bearerToken2
|
|
2022
2031
|
);
|
|
2023
2032
|
if (!res.success) {
|
|
2024
2033
|
throw res.err;
|
|
@@ -2101,7 +2110,11 @@ async function fetchTweets(userId, maxTweets, cursor, auth) {
|
|
|
2101
2110
|
}
|
|
2102
2111
|
const res = await requestApi(
|
|
2103
2112
|
userTweetsRequest.toRequestUrl(),
|
|
2104
|
-
auth
|
|
2113
|
+
auth,
|
|
2114
|
+
"GET",
|
|
2115
|
+
void 0,
|
|
2116
|
+
void 0,
|
|
2117
|
+
bearerToken2
|
|
2105
2118
|
);
|
|
2106
2119
|
if (!res.success) {
|
|
2107
2120
|
throw res.err;
|
|
@@ -2247,7 +2260,11 @@ async function getTweet(id, auth) {
|
|
|
2247
2260
|
tweetDetailRequest.variables.focalTweetId = id;
|
|
2248
2261
|
const res = await requestApi(
|
|
2249
2262
|
tweetDetailRequest.toRequestUrl(),
|
|
2250
|
-
auth
|
|
2263
|
+
auth,
|
|
2264
|
+
"GET",
|
|
2265
|
+
void 0,
|
|
2266
|
+
void 0,
|
|
2267
|
+
bearerToken2
|
|
2251
2268
|
);
|
|
2252
2269
|
if (!res.success) {
|
|
2253
2270
|
throw res.err;
|
|
@@ -2263,7 +2280,11 @@ async function getTweetAnonymous(id, auth) {
|
|
|
2263
2280
|
tweetResultByRestIdRequest.variables.tweetId = id;
|
|
2264
2281
|
const res = await requestApi(
|
|
2265
2282
|
tweetResultByRestIdRequest.toRequestUrl(),
|
|
2266
|
-
auth
|
|
2283
|
+
auth,
|
|
2284
|
+
"GET",
|
|
2285
|
+
void 0,
|
|
2286
|
+
void 0,
|
|
2287
|
+
bearerToken2
|
|
2267
2288
|
);
|
|
2268
2289
|
if (!res.success) {
|
|
2269
2290
|
throw res.err;
|