@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/esm/index.mjs
CHANGED
|
@@ -252,14 +252,17 @@ class TwitterGuestAuth {
|
|
|
252
252
|
}
|
|
253
253
|
return new Date(this.guestCreatedAt);
|
|
254
254
|
}
|
|
255
|
-
async installTo(headers) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
255
|
+
async installTo(headers, _url, bearerTokenOverride) {
|
|
256
|
+
const tokenToUse = bearerTokenOverride ?? this.bearerToken;
|
|
257
|
+
if (!bearerTokenOverride) {
|
|
258
|
+
if (this.shouldUpdate()) {
|
|
259
|
+
await this.updateGuestToken();
|
|
260
|
+
}
|
|
261
|
+
if (this.guestToken) {
|
|
262
|
+
headers.set("x-guest-token", this.guestToken);
|
|
263
|
+
}
|
|
261
264
|
}
|
|
262
|
-
headers.set("authorization", `Bearer ${
|
|
265
|
+
headers.set("authorization", `Bearer ${tokenToUse}`);
|
|
263
266
|
headers.set(
|
|
264
267
|
"user-agent",
|
|
265
268
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
|
|
@@ -496,13 +499,14 @@ async function generateTransactionId(url, fetchFn, method) {
|
|
|
496
499
|
|
|
497
500
|
const log$1 = debug("twitter-scraper:api");
|
|
498
501
|
const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
|
|
502
|
+
const bearerToken2 = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
|
|
499
503
|
async function jitter(maxMs) {
|
|
500
504
|
const jitter2 = Math.random() * maxMs;
|
|
501
505
|
await new Promise((resolve) => setTimeout(resolve, jitter2));
|
|
502
506
|
}
|
|
503
|
-
async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new Headers()) {
|
|
507
|
+
async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new Headers(), bearerTokenOverride) {
|
|
504
508
|
log$1(`Making ${method} request to ${url}`);
|
|
505
|
-
await auth.installTo(headers, url);
|
|
509
|
+
await auth.installTo(headers, url, bearerTokenOverride);
|
|
506
510
|
await platform.randomizeCiphers();
|
|
507
511
|
if (auth instanceof TwitterGuestAuth && auth.options?.experimental?.xClientTransactionId) {
|
|
508
512
|
const transactionId = await generateTransactionId(
|
|
@@ -743,8 +747,9 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
743
747
|
this.jar = new CookieJar();
|
|
744
748
|
}
|
|
745
749
|
}
|
|
746
|
-
async installTo(headers) {
|
|
747
|
-
|
|
750
|
+
async installTo(headers, _url, bearerTokenOverride) {
|
|
751
|
+
const tokenToUse = bearerTokenOverride ?? this.bearerToken;
|
|
752
|
+
headers.set("authorization", `Bearer ${tokenToUse}`);
|
|
748
753
|
headers.set(
|
|
749
754
|
"user-agent",
|
|
750
755
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
|
|
@@ -986,7 +991,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
986
991
|
"x-twitter-active-user": "yes",
|
|
987
992
|
"x-twitter-client-language": "en"
|
|
988
993
|
});
|
|
989
|
-
await this.installTo(headers);
|
|
994
|
+
await this.installTo(headers, onboardingTaskUrl);
|
|
990
995
|
if (this.options?.experimental?.xClientTransactionId) {
|
|
991
996
|
const transactionId = await generateTransactionId(
|
|
992
997
|
onboardingTaskUrl,
|
|
@@ -1163,7 +1168,14 @@ function parseProfile(legacy, isBlueVerified) {
|
|
|
1163
1168
|
async function getProfile(username, auth) {
|
|
1164
1169
|
const request = apiRequestFactory.createUserByScreenNameRequest();
|
|
1165
1170
|
request.variables.screen_name = username;
|
|
1166
|
-
const res = await requestApi(
|
|
1171
|
+
const res = await requestApi(
|
|
1172
|
+
request.toRequestUrl(),
|
|
1173
|
+
auth,
|
|
1174
|
+
"GET",
|
|
1175
|
+
void 0,
|
|
1176
|
+
void 0,
|
|
1177
|
+
bearerToken2
|
|
1178
|
+
);
|
|
1167
1179
|
if (!res.success) {
|
|
1168
1180
|
return res;
|
|
1169
1181
|
}
|
|
@@ -2017,7 +2029,11 @@ async function getTrends(auth) {
|
|
|
2017
2029
|
params.set("entity_tokens", "false");
|
|
2018
2030
|
const res = await requestApi(
|
|
2019
2031
|
`https://api.x.com/2/guide.json?${params.toString()}`,
|
|
2020
|
-
auth
|
|
2032
|
+
auth,
|
|
2033
|
+
"GET",
|
|
2034
|
+
void 0,
|
|
2035
|
+
void 0,
|
|
2036
|
+
bearerToken2
|
|
2021
2037
|
);
|
|
2022
2038
|
if (!res.success) {
|
|
2023
2039
|
throw res.err;
|
|
@@ -2100,7 +2116,11 @@ async function fetchTweets(userId, maxTweets, cursor, auth) {
|
|
|
2100
2116
|
}
|
|
2101
2117
|
const res = await requestApi(
|
|
2102
2118
|
userTweetsRequest.toRequestUrl(),
|
|
2103
|
-
auth
|
|
2119
|
+
auth,
|
|
2120
|
+
"GET",
|
|
2121
|
+
void 0,
|
|
2122
|
+
void 0,
|
|
2123
|
+
bearerToken2
|
|
2104
2124
|
);
|
|
2105
2125
|
if (!res.success) {
|
|
2106
2126
|
throw res.err;
|
|
@@ -2246,7 +2266,11 @@ async function getTweet(id, auth) {
|
|
|
2246
2266
|
tweetDetailRequest.variables.focalTweetId = id;
|
|
2247
2267
|
const res = await requestApi(
|
|
2248
2268
|
tweetDetailRequest.toRequestUrl(),
|
|
2249
|
-
auth
|
|
2269
|
+
auth,
|
|
2270
|
+
"GET",
|
|
2271
|
+
void 0,
|
|
2272
|
+
void 0,
|
|
2273
|
+
bearerToken2
|
|
2250
2274
|
);
|
|
2251
2275
|
if (!res.success) {
|
|
2252
2276
|
throw res.err;
|
|
@@ -2262,7 +2286,11 @@ async function getTweetAnonymous(id, auth) {
|
|
|
2262
2286
|
tweetResultByRestIdRequest.variables.tweetId = id;
|
|
2263
2287
|
const res = await requestApi(
|
|
2264
2288
|
tweetResultByRestIdRequest.toRequestUrl(),
|
|
2265
|
-
auth
|
|
2289
|
+
auth,
|
|
2290
|
+
"GET",
|
|
2291
|
+
void 0,
|
|
2292
|
+
void 0,
|
|
2293
|
+
bearerToken2
|
|
2266
2294
|
);
|
|
2267
2295
|
if (!res.success) {
|
|
2268
2296
|
throw res.err;
|