Skip to content

Instantly share code, notes, and snippets.

@fsjuhl
Last active October 25, 2019 13:48
Show Gist options
  • Save fsjuhl/989993e4c71b957204407ee4619605c6 to your computer and use it in GitHub Desktop.
Save fsjuhl/989993e4c71b957204407ee4619605c6 to your computer and use it in GitHub Desktop.
Replace targetTweetId, targetTweetTimestamp (remove the ·), cookie, CSRF_TOKEN (in headers) and ACCESS_TOKEN (also in headers).
const request = require("request-promise-native"),
fs = require("fs")
const targetTweetId = "1186731922766159872",
targetTweetTimestamp = new Date("9:50 PM Oct 22, 2019"),
cookie = "auth_token=; ct0=CSRF_TOKEN"
const twitter = request.defaults({
baseUrl: "https://api.twitter.com/",
headers: {
"Accept": "text/plain, */*; q=0.01",
"Authorization": "Bearer ACCESS_TOKEN",
"Origin": "https://tweetdeck.twitter.com",
"Referer": "https://tweetdeck.twitter.com/",
"Sec-Fetch-Mode": "cors",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"X-Csrf-Token": "CSRF_TOKEN",
"X-Twitter-Auth-Type": "OAuth2Session",
cookie
}
})
const actionsQuery = {
"model_version": "7",
"count": "40",
"skip_aggregation": "true",
"cards_platform": "Web-13",
"include_entities": "1",
"include_user_entities": "1",
"include_cards": "1",
"send_error_codes": "1",
"tweet_mode": "extended",
"include_ext_alt_text": "true",
"include_reply_count": "true",
}
const wait = ms => new Promise(res => setTimeout(res, ms))
let entries = []
async function getActions(maxId="") {
maxId
? actionsQuery.max_id = maxId
: delete actionsQuery.max_id
let cachedEntries = entries.length
const response = await twitter.get("1.1/activity/about_me.json", {
qs: actionsQuery
})
.then(JSON.parse)
response.forEach(action => {
if (action.action == "favorite" && action.targets[0].id_str == targetTweetId) {
entries.push({
name: action.sources[0].name,
id: action.sources[0].screen_name
})
}
})
if (new Date(response[response.length - 1].created_at) < targetTweetTimestamp) {
console.log(`Went through all entries. Total: ${entries.length}`)
return entries
} else {
console.log(`Added ${entries.length - cachedEntries} entries. Total: ${entries.length}. Fetching more...`)
await wait(200)
return await getActions(Number(response[response.length - 1].max_position) +1)
}
}
async function main() {
const things = await getActions()
things.forEach(e => console.log(`${e.name} (${e.id})`))
fs.writeFileSync("likes.json", JSON.stringify(things))
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment