Pulling data from Twitter to display on a blog or another webpage requires a little more effort than one might expect; however, Amit Agarwal, the author of the Digital Inspiration blog has crafted a relatively simple solution. Using a Twitter widget and a Google script, those who adopt this method will be able to aggregate tweets containing a specific hashtag. The video below was produced by Agarwal and demonstrates his method of displaying Twitter data in an RSS feed.
In the upper right hand corner of your Twitter homepage, select settings and then click the widgets link. Click the ‘create new‘ button and begin to configure your widget. Widgets can be configured in one of five ways; users’ timeline, favorites, list, search, and collections. Note that the text being displayed in the preview window is that which will be displayed in your RSS feed. Because the motivation for this blog post is based in the need to view a stream of tweets containing specific hashtags that is what I am going to do in this demonstration, but keep in mind that any of these configuration options can be used.
To aggregate tweets based on hashtags, it is necessary to create a search-based widget. Click the search tab and enter the hashtags that you would like to aggregate into the search box separated by the logical operators OR, or AND.
i.e. #GalileosWorld OR #oulynx OR #ouhos
Note that hashtags separated by OR will yeild search results containing any one of the hashtags listed whereas those separated by AND will only yield search results containing all of the listed hashtags. Once all relevant hashtags have been entered, click ‘create widget‘. A unique widget ID number will be created and the HTML embed code related to your widget will be generated. Copy this code into a plain-text editor and make note of the widget ID. It will be used later. If you notice in the preview window that fewer tweets than you expected are listed, note that only tweets less than one week old are indexed by the search API as noted by the developers documentation below.
Twitter’s search is optimized to serve relevant tweets to end-users in response to direct, non-recurring queries such as #hashtags, URLs, domains, and keywords. The Search API (which also powers Twitter’s search widget) is an interface to this search engine. Our search service is not meant to be an exhaustive archive of public tweets and not all tweets are indexed or returned. Some results are refined to better combat spam and increase relevance. Due to capacity constraints, the index currently only covers about a week’s worth of tweets.
Click here to make a copy of the necessary Google Script. Assuming that you have a Google Account, a copy of the script will be made and opened in your Google Drive. If you’re not familiar with scripting, don’t worry, none is necessary to get your feed working. Click ‘run‘ in the menu at the top of the page and then select Twitter_RSS. Upon doing this, the script is initialized and simply needs to be published. Click ‘Publish‘ in the menu at the top of the page and choose to Deploy as web app… and click the ‘Save New Version‘ button and then allow anyone access to the app by selecting ‘Anyone, even anonymous‘ from the dropdown and then deploy. The script should not be deleted from Google Drive for as long as you would like the RSS hashtag aggrigator to function.
Google Script will create a unique URL for your RSS aggrigator that looks similar to the following,
To give this script access to your Twitter widget, go back to the widget ID that is in the HTML that was pasted into a plain-text editor and append the widget ID to the end of the Google Script URL above preceeded by a question mark. The result should look something like the following,
Copy and past this URL into your browser’s address bar and you should see the XML of an RSS feed. This URL can be used by any RSS reader. In order to display this feed on a webpage or blog, a third-party application is needed. Instructions from this point forward will vary; however, obtaining the URL to the hashtag feed should be the most difficult part of displaying tweets as an RSS feed. To display RSS feeds on a WordPress blog, I have had success using the WP RSS Aggregator plugin.