@the-convocation/twitter-scraper 0.16.2 → 0.16.3
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 +10 -7
- package/dist/default/cjs/index.js.map +1 -1
- package/dist/default/esm/index.mjs +10 -7
- package/dist/default/esm/index.mjs.map +1 -1
- package/dist/node/cjs/index.cjs +10 -7
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.mjs +10 -7
- package/dist/node/esm/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -70,13 +70,13 @@ class AuthenticationError extends Error {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const log$
|
|
73
|
+
const log$3 = debug("twitter-scraper:rate-limit");
|
|
74
74
|
class WaitingRateLimitStrategy {
|
|
75
75
|
async onRateLimit({ response: res }) {
|
|
76
76
|
const xRateLimitLimit = res.headers.get("x-rate-limit-limit");
|
|
77
77
|
const xRateLimitRemaining = res.headers.get("x-rate-limit-remaining");
|
|
78
78
|
const xRateLimitReset = res.headers.get("x-rate-limit-reset");
|
|
79
|
-
log$
|
|
79
|
+
log$3(
|
|
80
80
|
`Rate limit event: limit=${xRateLimitLimit}, remaining=${xRateLimitRemaining}, reset=${xRateLimitReset}`
|
|
81
81
|
);
|
|
82
82
|
if (xRateLimitRemaining == "0" && xRateLimitReset) {
|
|
@@ -129,14 +129,14 @@ async function updateCookieJar(cookieJar, headers) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
const log$
|
|
132
|
+
const log$2 = debug("twitter-scraper:api");
|
|
133
133
|
const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
|
|
134
134
|
async function jitter(maxMs) {
|
|
135
135
|
const jitter2 = Math.random() * maxMs;
|
|
136
136
|
await new Promise((resolve) => setTimeout(resolve, jitter2));
|
|
137
137
|
}
|
|
138
138
|
async function requestApi(url, auth, method = "GET", platform = new Platform()) {
|
|
139
|
-
log$
|
|
139
|
+
log$2(`Making ${method} request to ${url}`);
|
|
140
140
|
const headers = new headersPolyfill.Headers();
|
|
141
141
|
await auth.installTo(headers, url);
|
|
142
142
|
await platform.randomizeCiphers();
|
|
@@ -163,7 +163,7 @@ async function requestApi(url, auth, method = "GET", platform = new Platform())
|
|
|
163
163
|
}
|
|
164
164
|
await updateCookieJar(auth.cookieJar(), res.headers);
|
|
165
165
|
if (res.status === 429) {
|
|
166
|
-
log$
|
|
166
|
+
log$2("Rate limit hit, waiting for retry...");
|
|
167
167
|
await auth.onRateLimit({
|
|
168
168
|
fetchParameters,
|
|
169
169
|
response: res
|
|
@@ -254,6 +254,7 @@ function addApiParams(params, includeTweetReplies) {
|
|
|
254
254
|
return params;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
const log$1 = debug("twitter-scraper:auth");
|
|
257
258
|
function withTransform(fetchFn, transform) {
|
|
258
259
|
return async (input, init) => {
|
|
259
260
|
const fetchArgs = await transform?.request?.(input, init) ?? [
|
|
@@ -357,6 +358,7 @@ class TwitterGuestAuth {
|
|
|
357
358
|
Authorization: `Bearer ${this.bearerToken}`,
|
|
358
359
|
Cookie: await this.getCookieString()
|
|
359
360
|
});
|
|
361
|
+
log$1(`Making POST request to ${guestActivateUrl}`);
|
|
360
362
|
const res = await this.fetch(guestActivateUrl, {
|
|
361
363
|
method: "POST",
|
|
362
364
|
headers,
|
|
@@ -707,6 +709,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
707
709
|
if ("flow_name" in data) {
|
|
708
710
|
onboardingTaskUrl = `https://api.x.com/1.1/onboarding/task.json?flow_name=${data.flow_name}`;
|
|
709
711
|
}
|
|
712
|
+
log(`Making POST request to ${onboardingTaskUrl}`);
|
|
710
713
|
const token = this.guestToken;
|
|
711
714
|
if (token == null) {
|
|
712
715
|
throw new AuthenticationError(
|
|
@@ -743,7 +746,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
743
746
|
}
|
|
744
747
|
return {
|
|
745
748
|
status: "error",
|
|
746
|
-
err
|
|
749
|
+
err
|
|
747
750
|
};
|
|
748
751
|
}
|
|
749
752
|
await updateCookieJar(this.jar, res.headers);
|
|
@@ -1274,7 +1277,7 @@ function parseTimelineTweetsV2(timeline) {
|
|
|
1274
1277
|
let bottomCursor;
|
|
1275
1278
|
let topCursor;
|
|
1276
1279
|
const tweets = [];
|
|
1277
|
-
const instructions = timeline.data?.user?.result?.
|
|
1280
|
+
const instructions = timeline.data?.user?.result?.timeline?.timeline?.instructions ?? [];
|
|
1278
1281
|
for (const instruction of instructions) {
|
|
1279
1282
|
const entries = instruction.entries ?? [];
|
|
1280
1283
|
for (const entry of entries) {
|