Created
September 8, 2023 18:42
-
-
Save infu/d112ca32ae65c5b948573fed72747238 to your computer and use it in GitHub Desktop.
Twitter get liked by
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TwitterApi } from "twitter-api-v2"; | |
import fs from "fs"; | |
const twitterClient = new TwitterApi( | |
"AAAAAAAAAAAAAAAAAAAAANv2bgEAAAAAq30nD5JxDUp3453453453452Bt1zJI%3DsGucipWI0FndiEu6yj26vKoKTphSczovppMG1123123123123" | |
); | |
// Tell typescript it's a readonly app | |
const client = twitterClient.readOnly; | |
const timeline = await client.v2.userTimeline("1455271745045270537", { | |
expansions: [ | |
], | |
}); | |
let likedby = {}; | |
let likedby_id = {}; | |
let max = 100; | |
let idx = 0; | |
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
for await (const tweet of timeline) { | |
console.log(tweet); | |
await delay(10000); | |
try { | |
const likingUsers = await client.v2.tweetLikedBy(tweet.id); | |
console.log(likingUsers); | |
if (likingUsers.data) | |
for (let user of likingUsers.data) { | |
likedby[user.username] = likedby[user.username] | |
? likedby[user.username] + 1 | |
: 1; | |
likedby_id[user.id] = likedby_id[user.id] ? likedby_id[user.id] + 1 : 1; | |
} | |
} catch (error) { | |
console.log(error); | |
} | |
idx += 1; | |
if (idx > max) break; | |
} | |
let sortable = []; | |
for (var user in likedby) { | |
sortable.push([user, likedby[user]]); | |
} | |
sortable = sortable.sort(function (a, b) { | |
return a[1] - b[1]; | |
}); | |
fs.writeFileSync("./likedby.json", JSON.stringify(sortable)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment