@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.
@@ -252,14 +252,17 @@ class TwitterGuestAuth {
252
252
  }
253
253
  return new Date(this.guestCreatedAt);
254
254
  }
255
- async installTo(headers) {
256
- if (this.shouldUpdate()) {
257
- await this.updateGuestToken();
258
- }
259
- if (this.guestToken) {
260
- headers.set("x-guest-token", this.guestToken);
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 ${this.bearerToken}`);
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
- headers.set("authorization", `Bearer ${this.bearerToken}`);
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,
@@ -2017,7 +2022,11 @@ async function getTrends(auth) {
2017
2022
  params.set("entity_tokens", "false");
2018
2023
  const res = await requestApi(
2019
2024
  `https://api.x.com/2/guide.json?${params.toString()}`,
2020
- auth
2025
+ auth,
2026
+ "GET",
2027
+ void 0,
2028
+ void 0,
2029
+ bearerToken2
2021
2030
  );
2022
2031
  if (!res.success) {
2023
2032
  throw res.err;
@@ -2100,7 +2109,11 @@ async function fetchTweets(userId, maxTweets, cursor, auth) {
2100
2109
  }
2101
2110
  const res = await requestApi(
2102
2111
  userTweetsRequest.toRequestUrl(),
2103
- auth
2112
+ auth,
2113
+ "GET",
2114
+ void 0,
2115
+ void 0,
2116
+ bearerToken2
2104
2117
  );
2105
2118
  if (!res.success) {
2106
2119
  throw res.err;
@@ -2246,7 +2259,11 @@ async function getTweet(id, auth) {
2246
2259
  tweetDetailRequest.variables.focalTweetId = id;
2247
2260
  const res = await requestApi(
2248
2261
  tweetDetailRequest.toRequestUrl(),
2249
- auth
2262
+ auth,
2263
+ "GET",
2264
+ void 0,
2265
+ void 0,
2266
+ bearerToken2
2250
2267
  );
2251
2268
  if (!res.success) {
2252
2269
  throw res.err;
@@ -2262,7 +2279,11 @@ async function getTweetAnonymous(id, auth) {
2262
2279
  tweetResultByRestIdRequest.variables.tweetId = id;
2263
2280
  const res = await requestApi(
2264
2281
  tweetResultByRestIdRequest.toRequestUrl(),
2265
- auth
2282
+ auth,
2283
+ "GET",
2284
+ void 0,
2285
+ void 0,
2286
+ bearerToken2
2266
2287
  );
2267
2288
  if (!res.success) {
2268
2289
  throw res.err;