Getting RSS feeds from twitter after updating API 1.1

    Due to twitter API updates from version 1.0 to version 1.1, requests for not receiving RSS feeds in the old style stopped working, like:

    This is due to the end of Twitter support for XML, RSS, and Atom output standards. The developers commented on their motives when making such a decision with the thesis that the proportion of such requests is small and can be disabled painlessly for users.

    But I am inclined to assume that there are users who would like, nevertheless, to see such functionality. For this group, the narrative below will be conducted.

    It was already in the Simpsons.

    There are many solutions to this problem. Probably the most appropriate is to create a widget in your Twitter account, followed by sending the data to google apps script for the subsequent formation of the RSS feed itself. This solution is described here .
    But not everyone has their own twitter account, and among those who do not have it, there may well be those who just want to read other people's tweets.

    Strictly speaking, the solution that I will offer below is not really reading someone’s twitter, it’s just looking for all the mentions of the username.

    Let's start

    To implement this “reading” without authorization, there is a ready-made script written in perl, the code of which is available at this link. It successfully interacts with twitter API 1.1 and provides search results in a convenient RSS form. In order to use it, you can copy it to any server that belongs to you and supports perl as the language for executing page scripts, or use the existing incarnation located at this address.
    But he is endowed with one significant drawback:
    $body = "";

    Here the fields “title” and “description” are encoded into special characters corresponding to the unicode table. There will be no problems with English-language tweets, but with Russian-language tweets they can. If your RSS client does not support decryption of such special characters, tweets will be unreadable.

    If you chose to install this script on your server, you just need to fix one line, otherwise there are two ways to solve this problem: on the remote side and on the local software side.

    I use Feed Notifier to read RSS. He has no processing for special characters. Support for their processing can be added independently, as this software is mostly written in python and the source code for it is available at this address.
    But in my case, it was decided to follow the path of full processing on the server side.
    Without further ado, a script was written for google apps script, which performs the task of converting encoded special characters. I will give his code:

    function doGet() {
      var response = UrlFetchApp.fetch("").getContentText("Windows-1251");
      var decode = XmlService.parse(response);
      var rootElement = decode.getRootElement();
      var channel = rootElement.getChildren("channel");
      var items = channel[0].getChildren("item");
      for (var i = 0; i < items.length; i++) {
        var title = items[i].getChildren("title");
        var description = items[i].getChildren("description");
        var decode_title = new XML('' + title[0].getText() + '');
        var decode_description = new XML('' + description[0].getText() + '');
      var output = XmlService.getPrettyFormat().format(decode);
      return ContentService.createTextOutput(output);  

    In this script, you only need to replace username with the name of the user whose updates you would like to track.
    The issue of creating and publishing a script is not complicated, but it has its own peculiarities. Firstly, after copying the script code into the newly created document, it must be saved. Secondly, it is necessary to drive it away so that the script requests permission for its execution, which we will give to it later (“Run” button). Thirdly, it must be published for launch from any source, incl. anonymous.

    As a result, we will have a link of the form:многобуквенный_идентификатор_скрипта/exec
    Great, now we have an RSS feed where all the special characters are replaced by their corresponding Unicode counterparts.
    For those whose RSS client supports HTTPS, this article ends. Feed Notifier does not support HTTPS. In principle, the problem of lack of support for HTTPS can be solved by making appropriate changes to the source code. But here I also went the server-side path.

    Since no sensitive information is transmitted through this channel, HTTPS traffic can quite be redirected to a regular HTTP channel. For this, I used a banal web proxy. Here is the web proxy can pass the address to go as a GET parameter, so I chose his name.

    Thus, as a result of all these manipulations, it is quite enough to feed the RSS client a link of the form:многобуквенный_идентификатор_скрипта/exec
    to get a fully functional version of the twitter feed’s RSS feed .

    If you want to read more than one person, it is enough to add another script of the same content to the same document, but with a different username.

    Maybe the method seems unnecessarily cumbersome, but it does not require any changes on the client side and allows you to group ribbons in an arbitrary order. Plus, it does not require a twitter account.

    Thanks for attention!

    Also popular now: