Skip to content

starkblaze01/Tweets-as-an-Image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tweets as an Image

To get recent tweets as an image of any user


This project is created using Canvas, Puppeteer, and Twitter API, initially created for integration with Github Profilinator( P.S. You can use it anywhere you want to add your Tweets in Image format 😉 ).

Note: The Heroku Dyno might be in Sleep mode, so retry after a few minutes in case the API didn't respond on first call

Blog

devto

Version 1:

APIs available for use:

  • https://tweets-as-an-image.herokuapp.com/?twitterHandle={your_twitter_handle_here} (Default count value: 1)
  • https://tweets-as-an-image.herokuapp.com/?twitterHandle={your_twitter_handle_here}&count={number_of_tweets_you_want_to_fecth}

Replace your_twitter_handle_here and number_of_tweets_you_want_to_fecth accordingly.


Note:

  • Retweets and comments are ignored.
  • Using Twitter API requires developer account and there's a rate limit over Twitter API usage which is 900 per user and 1500 per app with a window length of 15 minutes. Find more here.
  • So, for personal usage kindly please fork this repo and set up your own server on herokuapp

Steps to deploy your own fork:

  1. Create Developer Account on twitter.
  2. Register your app.
  3. Generate Bearer Token.
  4. Link your github repository on Heroku.
  5. Set environment variable TWITTER_OAUTH_TOKEN="Your bearer auth token".
  6. 🎉 Copy the deployed project and use it.(P.S. Don't forget to add twitter handle and count query at the end of url).

Sample Query Response for v1:

Version 2:

API available for use:

  • https://tweets-as-an-image.herokuapp.com/tweet?twitterHandle={your_twitter_handle}
  • https://tweets-as-an-image.herokuapp.com/tweet?twitterHandle={your_twitter_handle}&id={your_tweet_id}&theme={light_or_dark}&maxwidth={max_width_of_your_tweet_image}&height={height_of_the_image}&lang={language}

Optional Query Arguements:

  • id(User's Tweet ID, Default: user's last tweet)
  • theme (light or dark, Default: dark)
  • maxwidth (maxWidth of your tweet image(+10px for border will be added), Default: 550)
  • height (height of the image, Default: Min(2000, Height of your tweet))
  • lang (Languages Supported by twitter, check here, Default: en)

Note:

  • This project is using oembed response of the tweets, and the height of the any tweets are not fixed, as there can be media content too, so it is not returned in the response. Read more about it here. I am evaluating the height in the puppeteer itself, which is set to Minimum of 2000px and Height of Your Tweet. If you want to clip the part of the tweet, you can pass height as an optional query.
  • I am using Puppeteer, a headless Chromium based browser to load the oembed response and take the screenshot of it.
  • The Deployement part on heroku is same as the above one, but you need to add puppeteer buildpack in the deployement. You can know more about that here

Sample Query Response of v2:

Default Response:

Response with maxwidth set to 400, language to Spanish

Liked the project? Hit the star button to support!

Found a bug ? Create an issue here