Skip to content

Instantly share code, notes, and snippets.

@y-young
Last active February 19, 2021 12:04
Show Gist options
  • Save y-young/031291b39e425472a26d973bd9aa52ee to your computer and use it in GitHub Desktop.
Save y-young/031291b39e425472a26d973bd9aa52ee to your computer and use it in GitHub Desktop.
Twitter Followings Exporter
/*
Twitter Followings Exporter
Usage:
1. Go to https://twitter.com/username/following
2. Scoll down to the end
3. Filter requests in the network panel of DevTool like this:
https://twitter.com/i/api/graphql/aBcDeFGHijklMNopqRstUV/Following?variables=
4. Paste the whole response into `followings.json`
5. Run the script: `node twitter-followings-exporter.js`
6. Find other requests, repeat 4 and 5 until completed
*/
const fs = require("fs/promises");
(async () => {
let json = await fs.readFile("followings.json");
json = JSON.parse(json);
let entries;
for (let instruction of json.data.user.following_timeline.timeline
.instructions) {
if (instruction.type === "TimelineAddEntries") {
entries = instruction.entries;
break;
}
}
entries = entries.filter((entry) => entry.entryId.startsWith("user"));
const users = [];
for (const entry of entries) {
const user = entry.content.itemContent.user.legacy;
users.push(user.screen_name);
}
console.log(users);
let prevData;
try {
prevData = await fs.readFile("users.json");
prevData = JSON.parse(prevData);
} catch {
prevData = [];
}
await fs.writeFile(
"users.json",
JSON.stringify(prevData.concat(users), null, 2)
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment