@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
|
@@ -49,13 +49,13 @@ class AuthenticationError extends Error {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const log$
|
|
52
|
+
const log$3 = debug("twitter-scraper:rate-limit");
|
|
53
53
|
class WaitingRateLimitStrategy {
|
|
54
54
|
async onRateLimit({ response: res }) {
|
|
55
55
|
const xRateLimitLimit = res.headers.get("x-rate-limit-limit");
|
|
56
56
|
const xRateLimitRemaining = res.headers.get("x-rate-limit-remaining");
|
|
57
57
|
const xRateLimitReset = res.headers.get("x-rate-limit-reset");
|
|
58
|
-
log$
|
|
58
|
+
log$3(
|
|
59
59
|
`Rate limit event: limit=${xRateLimitLimit}, remaining=${xRateLimitRemaining}, reset=${xRateLimitReset}`
|
|
60
60
|
);
|
|
61
61
|
if (xRateLimitRemaining == "0" && xRateLimitReset) {
|
|
@@ -108,14 +108,14 @@ async function updateCookieJar(cookieJar, headers) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
const log$
|
|
111
|
+
const log$2 = debug("twitter-scraper:api");
|
|
112
112
|
const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
|
|
113
113
|
async function jitter(maxMs) {
|
|
114
114
|
const jitter2 = Math.random() * maxMs;
|
|
115
115
|
await new Promise((resolve) => setTimeout(resolve, jitter2));
|
|
116
116
|
}
|
|
117
117
|
async function requestApi(url, auth, method = "GET", platform = new Platform()) {
|
|
118
|
-
log$
|
|
118
|
+
log$2(`Making ${method} request to ${url}`);
|
|
119
119
|
const headers = new Headers();
|
|
120
120
|
await auth.installTo(headers, url);
|
|
121
121
|
await platform.randomizeCiphers();
|
|
@@ -142,7 +142,7 @@ async function requestApi(url, auth, method = "GET", platform = new Platform())
|
|
|
142
142
|
}
|
|
143
143
|
await updateCookieJar(auth.cookieJar(), res.headers);
|
|
144
144
|
if (res.status === 429) {
|
|
145
|
-
log$
|
|
145
|
+
log$2("Rate limit hit, waiting for retry...");
|
|
146
146
|
await auth.onRateLimit({
|
|
147
147
|
fetchParameters,
|
|
148
148
|
response: res
|
|
@@ -233,6 +233,7 @@ function addApiParams(params, includeTweetReplies) {
|
|
|
233
233
|
return params;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
const log$1 = debug("twitter-scraper:auth");
|
|
236
237
|
function withTransform(fetchFn, transform) {
|
|
237
238
|
return async (input, init) => {
|
|
238
239
|
const fetchArgs = await transform?.request?.(input, init) ?? [
|
|
@@ -336,6 +337,7 @@ class TwitterGuestAuth {
|
|
|
336
337
|
Authorization: `Bearer ${this.bearerToken}`,
|
|
337
338
|
Cookie: await this.getCookieString()
|
|
338
339
|
});
|
|
340
|
+
log$1(`Making POST request to ${guestActivateUrl}`);
|
|
339
341
|
const res = await this.fetch(guestActivateUrl, {
|
|
340
342
|
method: "POST",
|
|
341
343
|
headers,
|
|
@@ -686,6 +688,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
686
688
|
if ("flow_name" in data) {
|
|
687
689
|
onboardingTaskUrl = `https://api.x.com/1.1/onboarding/task.json?flow_name=${data.flow_name}`;
|
|
688
690
|
}
|
|
691
|
+
log(`Making POST request to ${onboardingTaskUrl}`);
|
|
689
692
|
const token = this.guestToken;
|
|
690
693
|
if (token == null) {
|
|
691
694
|
throw new AuthenticationError(
|
|
@@ -722,7 +725,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
722
725
|
}
|
|
723
726
|
return {
|
|
724
727
|
status: "error",
|
|
725
|
-
err
|
|
728
|
+
err
|
|
726
729
|
};
|
|
727
730
|
}
|
|
728
731
|
await updateCookieJar(this.jar, res.headers);
|
|
@@ -1253,7 +1256,7 @@ function parseTimelineTweetsV2(timeline) {
|
|
|
1253
1256
|
let bottomCursor;
|
|
1254
1257
|
let topCursor;
|
|
1255
1258
|
const tweets = [];
|
|
1256
|
-
const instructions = timeline.data?.user?.result?.
|
|
1259
|
+
const instructions = timeline.data?.user?.result?.timeline?.timeline?.instructions ?? [];
|
|
1257
1260
|
for (const instruction of instructions) {
|
|
1258
1261
|
const entries = instruction.entries ?? [];
|
|
1259
1262
|
for (const entry of entries) {
|