Last active
October 24, 2022 20:02
-
-
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
This file contains hidden or 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
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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go to twitter analytics, click on tweets, press
f12
on your keyboard, paste the exportData function into the console tab pressenter
. Then call the function by pastingexportData(Date.now(), Date.now() - ((24*60*60*1000) * 200))
(to export 200 days) and pressingenter
.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.