A Google Apps Script to scrape (parse) the Twitter Site and generate an RSS feed.
After Twitter closed down its public RSS feed in Summer 2013 there emerged several solutions to generate RSS feeds by either using the Twitter API or scraping the Twitter Site (e.g. RSS4Twittter or TwitRSS.me). These services however accumulated lots of users already and are suffering from the traffic generated by the users. This indeed leads to downtimes or countermeasures such as IP banning on excessive data use.
Luckily, the code from several of these projects is free so that anyone can deploy their own Twitter-to-RSS server. This project is meant for people who don't have an own server to deploy some of the other full-blown server-side solutions, e.g. from this Stack Exchange Discussion.
For this project you only need a Google account to upload the code to Google Apps Script. After doing so you will be able to access your RSS feeds through a public Google Apps URL and thus be able to add these feeds to your RSS Feed Reader.
As the public Twitter site is scraped to generate the RSS feed no login to Twitter or authentication is required to use this code.
This means you do not need to have a Twitter account to read Tweets through RSS. On the other hand this implies that only public Tweets can be accessed.
Currently the project only supports generating RSS feeds for a user timeline but no twitter searches or lists.
There exists a similar project Twitter-RSS-Google-Apps-Script,
which uses the Twitter API to connect to Twitter and generate the RSS feed.
This however requires that you have a Twitter Account and are able to authenticate to use the Twitter API.
The mentioned project also provides access to Twitter searches, favorites and lists besides user timelines.
You need to have a Google account (Gmail etc.) to be able to login to Google Apps Script.
There are two possibilities to setup the project:
- Use this link to create a new Google Apps project with the script code.
or alternatively create a scripts project by hand:
- Login to https://script.google.com/, go to "Start scripting" and create a new "Blank Project". Delete any code in your new project and copy & paste the content from the main-script.js file in this repository into the code editor of your newly created Google Script project. Save the file and give the project a name (e.g. "Twitter-to-RSS").
Next you need to make the script accessible through a public URL. Go to the Menu "Publish" and choose "Deploy as Web App". Then edit the comment for the Project version (e.g. "Initial Setup") and save that as a new version. Choose next "Execute the app as: me ([email protected])" and below give access to anyone, i.e. choose "Who has access to the app: Anyone, even anonymous". Finally, click "Deploy" to make the script accessible. This last step will give you the public URL for the project which will look similar to this one: https://script.google.com/macros/s/AKfycbzTTuLQDAU....../exec
If you setup and deploy the script for the first time the last "Deploy" step above will ask for authorization. The authorization is required by Google to allow the script to access resources on the web. Access to the web is necessary to fetch and parse the Twitter site. In the first popup window click "Continue" and then "Accept" in the following window that displays the permissions required by the script.
If no other error occurred in the above steps the script is now functional. On errors please file a bug describing your steps in the issue tracker.
Copy the URL from the previous step to your RSS Feed Reader and add the parameters for the Twitter username for which you want to parse the timeline like in the example below:
https://script.google.com/macros/s/AKfycbzTTuLQDAU....../exec***?user=ciderpunx*
Optional Parameters:
- Choose how many Tweets from the user's timeline should be parsed at once. If the number is too low, you might miss
some tweets if your Feed Reader pulls them unfrequently. If the number is too high, you might reach a quota on Google's
allowed daily traffic for scripts. So tweak this number depending on the volume of Tweets for a given user (default value is 100).
The example below shows the parameter:
https://script.google.com/macros/s/AKfycbzTTuLQDAU....../exec?user=ciderpunx&replies=on***&tweetscount=50* - Choose if you want to see only the user's Tweets or also the Replies by adding the parameter (default setting is off): https://script.google.com/macros/s/AKfycbzTTuLQDAU....../exec?user=ciderpunx***&replies=on* NOTE: Twitter has disabled showing the replies-stream for not logged in users. The above feature flag is ignored for now, until the feature might be brought back.
You already installed the script (see above for instructions) and would want to update it to a newer version from this repository that e.g. contains some bugfixes. To update the script you cannot use the copy link as described above in Setup as that would create a new project and result in a different public URL for your Feeds. Hence the way to update is to login to https://script.google.com/, go to "Start scripting" and choose the Project in the list of recent projects or by choosing "File -> Open" from the menu. Select the code in the script file and delete it. Then copy & paste the content from the main-script.js file in this repository into the code editor. Save the file and create a new project version by clicking "File -> Manage Versions" from the menu. That is, you enter a description for the new version (e.g. "fixes this bla bug") and choose ok. Next you can deploy this new version by choosing "Publish -> Deploy as Web App" form the menu and choosing the latest version from the drop down list. Press ok and from now the latest code will be executed when requesting the public URL of your feeds script.
The code is based on code from TwitRSS.me for which the repository can be found here. It has been extended, bugs have been fixed, new features added and it has been converted to a Google Apps Script to be easier to use.