@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.
@@ -273,14 +273,17 @@ class TwitterGuestAuth {
273
273
  }
274
274
  return new Date(this.guestCreatedAt);
275
275
  }
276
- async installTo(headers) {
277
- if (this.shouldUpdate()) {
278
- await this.updateGuestToken();
279
- }
280
- if (this.guestToken) {
281
- headers.set("x-guest-token", this.guestToken);
276
+ async installTo(headers, _url, bearerTokenOverride) {
277
+ const tokenToUse = bearerTokenOverride ?? this.bearerToken;
278
+ if (!bearerTokenOverride) {
279
+ if (this.shouldUpdate()) {
280
+ await this.updateGuestToken();
281
+ }
282
+ if (this.guestToken) {
283
+ headers.set("x-guest-token", this.guestToken);
284
+ }
282
285
  }
283
- headers.set("authorization", `Bearer ${this.bearerToken}`);
286
+ headers.set("authorization", `Bearer ${tokenToUse}`);
284
287
  headers.set(
285
288
  "user-agent",
286
289
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
@@ -517,13 +520,14 @@ async function generateTransactionId(url, fetchFn, method) {
517
520
 
518
521
  const log$1 = debug("twitter-scraper:api");
519
522
  const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
523
+ const bearerToken2 = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
520
524
  async function jitter(maxMs) {
521
525
  const jitter2 = Math.random() * maxMs;
522
526
  await new Promise((resolve) => setTimeout(resolve, jitter2));
523
527
  }
524
- async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new headersPolyfill.Headers()) {
528
+ async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new headersPolyfill.Headers(), bearerTokenOverride) {
525
529
  log$1(`Making ${method} request to ${url}`);
526
- await auth.installTo(headers, url);
530
+ await auth.installTo(headers, url, bearerTokenOverride);
527
531
  await platform.randomizeCiphers();
528
532
  if (auth instanceof TwitterGuestAuth && auth.options?.experimental?.xClientTransactionId) {
529
533
  const transactionId = await generateTransactionId(
@@ -764,8 +768,9 @@ class TwitterUserAuth extends TwitterGuestAuth {
764
768
  this.jar = new toughCookie.CookieJar();
765
769
  }
766
770
  }
767
- async installTo(headers) {
768
- headers.set("authorization", `Bearer ${this.bearerToken}`);
771
+ async installTo(headers, _url, bearerTokenOverride) {
772
+ const tokenToUse = bearerTokenOverride ?? this.bearerToken;
773
+ headers.set("authorization", `Bearer ${tokenToUse}`);
769
774
  headers.set(
770
775
  "user-agent",
771
776
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
@@ -1007,7 +1012,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
1007
1012
  "x-twitter-active-user": "yes",
1008
1013
  "x-twitter-client-language": "en"
1009
1014
  });
1010
- await this.installTo(headers);
1015
+ await this.installTo(headers, onboardingTaskUrl);
1011
1016
  if (this.options?.experimental?.xClientTransactionId) {
1012
1017
  const transactionId = await generateTransactionId(
1013
1018
  onboardingTaskUrl,
@@ -2038,7 +2043,11 @@ async function getTrends(auth) {
2038
2043
  params.set("entity_tokens", "false");
2039
2044
  const res = await requestApi(
2040
2045
  `https://api.x.com/2/guide.json?${params.toString()}`,
2041
- auth
2046
+ auth,
2047
+ "GET",
2048
+ void 0,
2049
+ void 0,
2050
+ bearerToken2
2042
2051
  );
2043
2052
  if (!res.success) {
2044
2053
  throw res.err;
@@ -2121,7 +2130,11 @@ async function fetchTweets(userId, maxTweets, cursor, auth) {
2121
2130
  }
2122
2131
  const res = await requestApi(
2123
2132
  userTweetsRequest.toRequestUrl(),
2124
- auth
2133
+ auth,
2134
+ "GET",
2135
+ void 0,
2136
+ void 0,
2137
+ bearerToken2
2125
2138
  );
2126
2139
  if (!res.success) {
2127
2140
  throw res.err;
@@ -2267,7 +2280,11 @@ async function getTweet(id, auth) {
2267
2280
  tweetDetailRequest.variables.focalTweetId = id;
2268
2281
  const res = await requestApi(
2269
2282
  tweetDetailRequest.toRequestUrl(),
2270
- auth
2283
+ auth,
2284
+ "GET",
2285
+ void 0,
2286
+ void 0,
2287
+ bearerToken2
2271
2288
  );
2272
2289
  if (!res.success) {
2273
2290
  throw res.err;
@@ -2283,7 +2300,11 @@ async function getTweetAnonymous(id, auth) {
2283
2300
  tweetResultByRestIdRequest.variables.tweetId = id;
2284
2301
  const res = await requestApi(
2285
2302
  tweetResultByRestIdRequest.toRequestUrl(),
2286
- auth
2303
+ auth,
2304
+ "GET",
2305
+ void 0,
2306
+ void 0,
2307
+ bearerToken2
2287
2308
  );
2288
2309
  if (!res.success) {
2289
2310
  throw res.err;