@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.
@@ -250,14 +250,17 @@ class TwitterGuestAuth {
250
250
  }
251
251
  return new Date(this.guestCreatedAt);
252
252
  }
253
- async installTo(headers) {
254
- if (this.shouldUpdate()) {
255
- await this.updateGuestToken();
256
- }
257
- if (this.guestToken) {
258
- headers.set("x-guest-token", this.guestToken);
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 ${this.bearerToken}`);
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
- headers.set("authorization", `Bearer ${this.bearerToken}`);
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,
@@ -1164,7 +1169,14 @@ function parseProfile(legacy, isBlueVerified) {
1164
1169
  async function getProfile(username, auth) {
1165
1170
  const request = apiRequestFactory.createUserByScreenNameRequest();
1166
1171
  request.variables.screen_name = username;
1167
- const res = await requestApi(request.toRequestUrl(), auth);
1172
+ const res = await requestApi(
1173
+ request.toRequestUrl(),
1174
+ auth,
1175
+ "GET",
1176
+ void 0,
1177
+ void 0,
1178
+ bearerToken2
1179
+ );
1168
1180
  if (!res.success) {
1169
1181
  return res;
1170
1182
  }
@@ -2018,7 +2030,11 @@ async function getTrends(auth) {
2018
2030
  params.set("entity_tokens", "false");
2019
2031
  const res = await requestApi(
2020
2032
  `https://api.x.com/2/guide.json?${params.toString()}`,
2021
- auth
2033
+ auth,
2034
+ "GET",
2035
+ void 0,
2036
+ void 0,
2037
+ bearerToken2
2022
2038
  );
2023
2039
  if (!res.success) {
2024
2040
  throw res.err;
@@ -2101,7 +2117,11 @@ async function fetchTweets(userId, maxTweets, cursor, auth) {
2101
2117
  }
2102
2118
  const res = await requestApi(
2103
2119
  userTweetsRequest.toRequestUrl(),
2104
- auth
2120
+ auth,
2121
+ "GET",
2122
+ void 0,
2123
+ void 0,
2124
+ bearerToken2
2105
2125
  );
2106
2126
  if (!res.success) {
2107
2127
  throw res.err;
@@ -2247,7 +2267,11 @@ async function getTweet(id, auth) {
2247
2267
  tweetDetailRequest.variables.focalTweetId = id;
2248
2268
  const res = await requestApi(
2249
2269
  tweetDetailRequest.toRequestUrl(),
2250
- auth
2270
+ auth,
2271
+ "GET",
2272
+ void 0,
2273
+ void 0,
2274
+ bearerToken2
2251
2275
  );
2252
2276
  if (!res.success) {
2253
2277
  throw res.err;
@@ -2263,7 +2287,11 @@ async function getTweetAnonymous(id, auth) {
2263
2287
  tweetResultByRestIdRequest.variables.tweetId = id;
2264
2288
  const res = await requestApi(
2265
2289
  tweetResultByRestIdRequest.toRequestUrl(),
2266
- auth
2290
+ auth,
2291
+ "GET",
2292
+ void 0,
2293
+ void 0,
2294
+ bearerToken2
2267
2295
  );
2268
2296
  if (!res.success) {
2269
2297
  throw res.err;