Skip to content

Instantly share code, notes, and snippets.

@h43z
Last active October 24, 2022 20:02
Show Gist options
  • Save h43z/0abee9969e04f5469ad9ce7786bb2898 to your computer and use it in GitHub Desktop.
Save h43z/0abee9969e04f5469ad9ce7786bb2898 to your computer and use it in GitHub Desktop.
Export more than 90 days of tweet activity data from https://analytics.twitter.com
function exportData(start, end){
const checkTimer = setInterval(async () => {
const resp = await fetch(`${document.URL}/export.json?start_time=${start}&end_time=${end}&lang=en&export_type=by_tweet`, {
method: "post"
})
const json = await resp.json()
if(json.status === 'Available'){
clearInterval(checkTimer)
return download()
}
console.log(`Export not ready, status ${json.status}`)
}, 2000)
async function download(){
const resp = await fetch(`${document.URL}/bundle?start_time=${start}&end_time=${end}&lang=en&export_type=by_tweet`)
const blob = await resp.blob()
const a = document.createElement("a")
a.href = URL.createObjectURL(blob)
a.download = `tweet_activity_${start}_${end}.csv`
document.body.appendChild(a)
a.click()
}
}
@h43z
Copy link
Author

h43z commented Apr 23, 2019

Go to twitter analytics, click on tweets, press f12 on your keyboard, paste the exportData function into the console tab press enter. Then call the function by pasting
exportData(Date.now(), Date.now() - ((24*60*60*1000) * 200)) (to export 200 days) and pressing enter.

Tested it up to 365 days and worked fine. But it takes some time until the file is ready for download.
You will see a bunch of Export not ready, status Pending until the download is initiated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment