@the-convocation/twitter-scraper 0.16.2 → 0.16.4
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 +14 -9
- package/dist/default/cjs/index.js.map +1 -1
- package/dist/default/esm/index.mjs +14 -9
- package/dist/default/esm/index.mjs.map +1 -1
- package/dist/node/cjs/index.cjs +14 -9
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.mjs +14 -9
- package/dist/node/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +9 -0
- package/package.json +1 -1
package/dist/node/esm/index.mjs
CHANGED
|
@@ -51,13 +51,13 @@ class AuthenticationError extends Error {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const log$
|
|
54
|
+
const log$3 = debug("twitter-scraper:rate-limit");
|
|
55
55
|
class WaitingRateLimitStrategy {
|
|
56
56
|
async onRateLimit({ response: res }) {
|
|
57
57
|
const xRateLimitLimit = res.headers.get("x-rate-limit-limit");
|
|
58
58
|
const xRateLimitRemaining = res.headers.get("x-rate-limit-remaining");
|
|
59
59
|
const xRateLimitReset = res.headers.get("x-rate-limit-reset");
|
|
60
|
-
log$
|
|
60
|
+
log$3(
|
|
61
61
|
`Rate limit event: limit=${xRateLimitLimit}, remaining=${xRateLimitRemaining}, reset=${xRateLimitReset}`
|
|
62
62
|
);
|
|
63
63
|
if (xRateLimitRemaining == "0" && xRateLimitReset) {
|
|
@@ -107,14 +107,14 @@ async function updateCookieJar(cookieJar, headers) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const log$
|
|
110
|
+
const log$2 = debug("twitter-scraper:api");
|
|
111
111
|
const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
|
|
112
112
|
async function jitter(maxMs) {
|
|
113
113
|
const jitter2 = Math.random() * maxMs;
|
|
114
114
|
await new Promise((resolve) => setTimeout(resolve, jitter2));
|
|
115
115
|
}
|
|
116
116
|
async function requestApi(url, auth, method = "GET", platform = new Platform()) {
|
|
117
|
-
log$
|
|
117
|
+
log$2(`Making ${method} request to ${url}`);
|
|
118
118
|
const headers = new Headers();
|
|
119
119
|
await auth.installTo(headers, url);
|
|
120
120
|
await platform.randomizeCiphers();
|
|
@@ -141,7 +141,7 @@ async function requestApi(url, auth, method = "GET", platform = new Platform())
|
|
|
141
141
|
}
|
|
142
142
|
await updateCookieJar(auth.cookieJar(), res.headers);
|
|
143
143
|
if (res.status === 429) {
|
|
144
|
-
log$
|
|
144
|
+
log$2("Rate limit hit, waiting for retry...");
|
|
145
145
|
await auth.onRateLimit({
|
|
146
146
|
fetchParameters,
|
|
147
147
|
response: res
|
|
@@ -232,6 +232,7 @@ function addApiParams(params, includeTweetReplies) {
|
|
|
232
232
|
return params;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
const log$1 = debug("twitter-scraper:auth");
|
|
235
236
|
function withTransform(fetchFn, transform) {
|
|
236
237
|
return async (input, init) => {
|
|
237
238
|
const fetchArgs = await transform?.request?.(input, init) ?? [
|
|
@@ -335,6 +336,7 @@ class TwitterGuestAuth {
|
|
|
335
336
|
Authorization: `Bearer ${this.bearerToken}`,
|
|
336
337
|
Cookie: await this.getCookieString()
|
|
337
338
|
});
|
|
339
|
+
log$1(`Making POST request to ${guestActivateUrl}`);
|
|
338
340
|
const res = await this.fetch(guestActivateUrl, {
|
|
339
341
|
method: "POST",
|
|
340
342
|
headers,
|
|
@@ -685,6 +687,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
685
687
|
if ("flow_name" in data) {
|
|
686
688
|
onboardingTaskUrl = `https://api.x.com/1.1/onboarding/task.json?flow_name=${data.flow_name}`;
|
|
687
689
|
}
|
|
690
|
+
log(`Making POST request to ${onboardingTaskUrl}`);
|
|
688
691
|
const token = this.guestToken;
|
|
689
692
|
if (token == null) {
|
|
690
693
|
throw new AuthenticationError(
|
|
@@ -721,7 +724,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
|
|
|
721
724
|
}
|
|
722
725
|
return {
|
|
723
726
|
status: "error",
|
|
724
|
-
err
|
|
727
|
+
err
|
|
725
728
|
};
|
|
726
729
|
}
|
|
727
730
|
await updateCookieJar(this.jar, res.headers);
|
|
@@ -1196,7 +1199,8 @@ function parseLegacyTweet(coreUser, user, tweet, editControl) {
|
|
|
1196
1199
|
const parsedResult = parseLegacyTweet(
|
|
1197
1200
|
retweetedStatusResult?.core?.user_results?.result?.core,
|
|
1198
1201
|
retweetedStatusResult?.core?.user_results?.result?.legacy,
|
|
1199
|
-
retweetedStatusResult?.legacy
|
|
1202
|
+
retweetedStatusResult?.legacy,
|
|
1203
|
+
retweetedStatusResult?.edit_control?.edit_control_initial
|
|
1200
1204
|
);
|
|
1201
1205
|
if (parsedResult.success) {
|
|
1202
1206
|
tw.retweetedStatus = parsedResult.tweet;
|
|
@@ -1224,7 +1228,8 @@ function parseResult(result) {
|
|
|
1224
1228
|
const tweetResult = parseLegacyTweet(
|
|
1225
1229
|
result?.core?.user_results?.result?.core,
|
|
1226
1230
|
result?.core?.user_results?.result?.legacy,
|
|
1227
|
-
result?.legacy
|
|
1231
|
+
result?.legacy,
|
|
1232
|
+
result?.edit_control?.edit_control_initial
|
|
1228
1233
|
);
|
|
1229
1234
|
if (!tweetResult.success) {
|
|
1230
1235
|
return tweetResult;
|
|
@@ -1252,7 +1257,7 @@ function parseTimelineTweetsV2(timeline) {
|
|
|
1252
1257
|
let bottomCursor;
|
|
1253
1258
|
let topCursor;
|
|
1254
1259
|
const tweets = [];
|
|
1255
|
-
const instructions = timeline.data?.user?.result?.
|
|
1260
|
+
const instructions = timeline.data?.user?.result?.timeline?.timeline?.instructions ?? [];
|
|
1256
1261
|
for (const instruction of instructions) {
|
|
1257
1262
|
const entries = instruction.entries ?? [];
|
|
1258
1263
|
for (const entry of entries) {
|