Skip to content

trungdq88/real-time-twitter-banner

Repository files navigation

Real-time Twitter Header

This is a fun little experiment with Twitter API. See my tweet!

CleanShot 2021-05-08 at 20 41 05@2x

How to setup for your Twitter

Just fill in your information in the emojiheader.js script.

const TWITTER_HANDLE = '@tdinh_me';
const credentials = {
  consumer_key: 'YOUR KEY HERE',
  consumer_secret: 'YOUR KEY HERE',
  access_token_key: 'YOUR KEY HERE',
  access_token_secret: 'YOUR KEY HERE'
};

To get the API keys, you need to apply for a Twitter Developer account. It's free and take ~5 minutes.

Lastly, change the default banner 1500x500.png or use the default one here. Make sure it's a png (as in the mimetype, not just the file extension).

PS: would be nice if you could leave the credit :P

Run the script

Install dependencies:

yarn

or

npm install

Note: if you are using an M1 MacBook, the image processing dependency may fail to install. Use another laptop or run it on a server.

Start the app:

node emojiheader.js

Keep it running and have fun!

How the script works

Read my thread here. Summary:

  1. Fetch your replies using Twitter API. (Rate limit: 180 requests per 15 mins)
  2. Filter the emojis from the text (not easy as it seems).
  3. Slap the emojis into the default banner (emoji images provided by twemoji).
  4. Update your profile banner using Twitter API. (Rate limit: 30 requests per 15 mins)

The script fetch new replies every 6 seconds (to avoid rate limit), then update the banner only if there are new emojis.

The delay between reply and banner update is between 6s to 15s.

Most importantly

Follow me on Twitter! https://twitter.com/tdinh_me

Thanks!

License

AGPLv3