Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/node-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"start:cjs": "node src/index.cjs"
},
"dependencies": {
"@the-convocation/twitter-scraper": "file:../../"
"@the-convocation/twitter-scraper": "file:../../",
"dotenv": "^17.2.3"
},
"devDependencies": {}
}
10 changes: 9 additions & 1 deletion examples/node-integration/src/index.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const assert = require('node:assert');
const dotenv = require('dotenv');
const { Scraper } = require('@the-convocation/twitter-scraper');

dotenv.config({ path: '../../.env.local' });

// Debug logging to show that the Node.js build is being loaded
console.log(
`Loaded @the-convocation/twitter-scraper from ${require.resolve(
Expand All @@ -21,7 +24,12 @@ const email = process.env['TWITTER_EMAIL'];

assert(username && password && email);

const scraper = new Scraper();
const scraper = new Scraper({
experimental: {
xClientTransactionId: true,
xpff: true,
},
});

const main = async () => {
await scraper.login(username, password, email);
Expand Down
10 changes: 9 additions & 1 deletion examples/node-integration/src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import assert from 'node:assert';
import dotenv from 'dotenv';
import { Scraper } from '@the-convocation/twitter-scraper';

dotenv.config({ path: '../../.env.local' });

// Debug logging to show that the Node.js build is being loaded
console.log(
`Loaded @the-convocation/twitter-scraper from ${import.meta.resolve(
Expand All @@ -20,7 +23,12 @@ const email = process.env['TWITTER_EMAIL'];

assert(username && password && email);

const scraper = new Scraper();
const scraper = new Scraper({
experimental: {
xClientTransactionId: true,
xpff: true,
},
});
await scraper.login(username, password, email);

const tweet = await scraper.getTweet('1585338303800578049');
Expand Down
133 changes: 132 additions & 1 deletion examples/node-integration/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@
integrity sha512-m+A3zFSI87TCtoz6vQCSnd+t/kDKL78JmzhKYkON+7SnHSa+794qraIVpm6ozFGK+5svnVOt1LJ7BUEhGkIvgg==

"@the-convocation/twitter-scraper@file:../..":
version "0.12.0"
version "0.20.0"
dependencies:
"@sinclair/typebox" "^0.32.20"
cross-fetch "^4.0.0-alpha.5"
debug "^4.4.1"
headers-polyfill "^3.1.2"
json-stable-stringify "^1.0.2"
linkedom "^0.18.12"
otpauth "^9.2.2"
set-cookie-parser "^2.6.0"
tough-cookie "^4.1.2"
tslib "^2.5.2"
x-client-transaction-id "^0.1.9"

boolbase@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
integrity sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==

call-bind@^1.0.5:
version "1.0.7"
Expand All @@ -42,6 +50,34 @@ cross-fetch@^4.0.0-alpha.5:
dependencies:
node-fetch "^2.6.12"

css-select@^5.1.0:
version "5.2.2"
resolved "https://registry.yarnpkg.com/css-select/-/css-select-5.2.2.tgz#01b6e8d163637bb2dd6c982ca4ed65863682786e"
integrity sha512-TizTzUddG/xYLA3NXodFM0fSbNizXjOKhqiQQwvhlspadZokn1KDy0NZFS0wuEubIYAV5/c1/lAr0TaaFXEXzw==
dependencies:
boolbase "^1.0.0"
css-what "^6.1.0"
domhandler "^5.0.2"
domutils "^3.0.1"
nth-check "^2.0.1"

css-what@^6.1.0:
version "6.2.2"
resolved "https://registry.yarnpkg.com/css-what/-/css-what-6.2.2.tgz#cdcc8f9b6977719fdfbd1de7aec24abf756b9dea"
integrity sha512-u/O3vwbptzhMs3L1fQE82ZSLHQQfto5gyZzwteVIEyeaY5Fc7R4dapF/BvRoSYFeqfBk4m0V1Vafq5Pjv25wvA==

cssom@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.5.0.tgz#d254fa92cd8b6fbd83811b9fbaed34663cc17c36"
integrity sha512-iKuQcq+NdHqlAcwUY0o/HL69XQrUaQdMjmStJ8JFmUaiiQErlhrmuigkg/CU4E2J0IyUKUrMAgl36TvN67MqTw==

debug@^4.4.1:
version "4.4.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.3.tgz#c6ae432d9bd9662582fce08709b038c58e9e3d6a"
integrity sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==
dependencies:
ms "^2.1.3"

define-data-property@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.4.tgz#894dc141bb7d3060ae4366f6a0107e68fbe48c5e"
Expand All @@ -51,6 +87,51 @@ define-data-property@^1.1.4:
es-errors "^1.3.0"
gopd "^1.0.1"

dom-serializer@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-2.0.0.tgz#e41b802e1eedf9f6cae183ce5e622d789d7d8e53"
integrity sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==
dependencies:
domelementtype "^2.3.0"
domhandler "^5.0.2"
entities "^4.2.0"

domelementtype@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.3.0.tgz#5c45e8e869952626331d7aab326d01daf65d589d"
integrity sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==

domhandler@^5.0.2, domhandler@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-5.0.3.tgz#cc385f7f751f1d1fc650c21374804254538c7d31"
integrity sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==
dependencies:
domelementtype "^2.3.0"

domutils@^3.0.1, domutils@^3.2.1:
version "3.2.2"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-3.2.2.tgz#edbfe2b668b0c1d97c24baf0f1062b132221bc78"
integrity sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==
dependencies:
dom-serializer "^2.0.0"
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^17.2.3:
version "17.2.3"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-17.2.3.tgz#ad995d6997f639b11065f419a22fabf567cdb9a2"
integrity sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==

entities@^4.2.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48"
integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==

entities@^6.0.0:
version "6.0.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-6.0.1.tgz#c28c34a43379ca7f61d074130b2f5f7020a30694"
integrity sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==

es-define-property@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/es-define-property/-/es-define-property-1.0.0.tgz#c7faefbdff8b2696cf5f46921edfb77cc4ba3845"
Expand Down Expand Up @@ -115,6 +196,21 @@ headers-polyfill@^3.1.2:
resolved "https://registry.yarnpkg.com/headers-polyfill/-/headers-polyfill-3.3.0.tgz#67c6ef7b72d4c8cac832ad5936f5b3a56e7b705a"
integrity sha512-5e57etwBpNcDc0b6KCVWEh/Ro063OxPvzVimUdM0/tsYM/T7Hfy3kknIGj78SFTOhNd8AZY41U8mOHoO4LzmIQ==

html-escaper@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-3.0.3.tgz#4d336674652beb1dcbc29ef6b6ba7f6be6fdfed6"
integrity sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ==

htmlparser2@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-10.0.0.tgz#77ad249037b66bf8cc99c6e286ef73b83aeb621d"
integrity sha512-TwAZM+zE5Tq3lrEHvOlvwgj1XLWQCtaaibSN11Q+gGBAS7Y1uZSWwXXRe4iF6OXnaq1riyQAPFOBtYc77Mxq0g==
dependencies:
domelementtype "^2.3.0"
domhandler "^5.0.3"
domutils "^3.2.1"
entities "^6.0.0"

isarray@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723"
Expand All @@ -135,13 +231,36 @@ jsonify@^0.0.1:
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.1.tgz#2aa3111dae3d34a0f151c63f3a45d995d9420978"
integrity sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==

linkedom@^0.18.12, linkedom@^0.18.9:
version "0.18.12"
resolved "https://registry.yarnpkg.com/linkedom/-/linkedom-0.18.12.tgz#a8b1a1942b567dcb1888093df311055da1349a14"
integrity sha512-jalJsOwIKuQJSeTvsgzPe9iJzyfVaEJiEXl+25EkKevsULHvMJzpNqwvj1jOESWdmgKDiXObyjOYwlUqG7wo1Q==
dependencies:
css-select "^5.1.0"
cssom "^0.5.0"
html-escaper "^3.0.3"
htmlparser2 "^10.0.0"
uhyphen "^0.2.0"

ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

node-fetch@^2.6.12:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

nth-check@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.1.1.tgz#c9eab428effce36cd6b92c924bdb000ef1f1ed1d"
integrity sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==
dependencies:
boolbase "^1.0.0"

object-keys@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
Expand Down Expand Up @@ -211,6 +330,11 @@ tslib@^2.5.2:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0"
integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==

uhyphen@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/uhyphen/-/uhyphen-0.2.0.tgz#8fdf0623314486e020a3c00ee5cc7a12fe722b81"
integrity sha512-qz3o9CHXmJJPGBdqzab7qAYuW8kQGKNEuoHFYrBwV6hWIMcpAmxDLXojcHfFr9US1Pe6zUswEIJIbLI610fuqA==

universalify@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
Expand All @@ -236,3 +360,10 @@ whatwg-url@^5.0.0:
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

x-client-transaction-id@^0.1.9:
version "0.1.9"
resolved "https://registry.yarnpkg.com/x-client-transaction-id/-/x-client-transaction-id-0.1.9.tgz#3bb0359268a481f66edf39c0aaa195d73195e849"
integrity sha512-CES4zgkJ0wbfFWm0qgdKphthyb+L7lVHymgOY15v6ivcWSx5p9lp5kzAed+BuqJSP7bS0GbQyJ16ONkRthgsUw==
dependencies:
linkedom "^0.18.9"
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scraper",
"crawler"
],
"version": "0.19.1",
"version": "0.20.0",
"main": "dist/default/cjs/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
Expand Down Expand Up @@ -42,21 +42,23 @@
"docs:deploy": "yarn docs:generate && gh-pages -d docs",
"format": "prettier --write src/**/*.ts examples/**/*.{ts,js,tsx}",
"prepare": "husky install",
"test": "jest"
"test": "jest --runInBand --forceExit"
},
"dependencies": {
"@sinclair/typebox": "^0.32.20",
"cross-fetch": "^4.0.0-alpha.5",
"debug": "^4.4.1",
"headers-polyfill": "^3.1.2",
"json-stable-stringify": "^1.0.2",
"linkedom": "^0.18.12",
"otpauth": "^9.2.2",
"set-cookie-parser": "^2.6.0",
"tough-cookie": "^4.1.2",
"tslib": "^2.5.2"
"tslib": "^2.5.2",
"x-client-transaction-id": "^0.1.9"
},
"peerDependencies": {
"cycletls": "^2.0.4"
"cycletls": "^2.0.5"
},
"peerDependenciesMeta": {
"cycletls": {
Expand Down
15 changes: 14 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { FetchParameters } from './api-types';
import { TwitterAuth } from './auth';
import { TwitterAuth, TwitterGuestAuth } from './auth';
import { ApiError } from './errors';
import { Platform, PlatformExtensions } from './platform';
import { updateCookieJar } from './requests';
import { Headers } from 'headers-polyfill';
import debug from 'debug';
import { generateTransactionId } from './xctxid';

const log = debug('twitter-scraper:api');

Expand Down Expand Up @@ -63,6 +64,18 @@ export async function requestApi<T>(
await auth.installTo(headers, url);
await platform.randomizeCiphers();

if (
auth instanceof TwitterGuestAuth &&
auth.options?.experimental?.xClientTransactionId
) {
const transactionId = await generateTransactionId(
url,
auth.fetch.bind(auth),
method,
);
headers.set('x-client-transaction-id', transactionId);
}

let res: Response;
do {
const fetchParameters: FetchParameters = [
Expand Down
Loading
Loading