Create a live twitter feed aggregator module for Drupal 6

The next thing I am going to be doing is to create a module for my site. I have had a look at similar projects and non seem to quite fit the bill.

What I want is a live stream from twitter based on search terms and while the Twitter Search Feeds and Activity Stream come close to providing the functionality, I don't want the items produced to populate my database and add nodes to the website, it is just going to display what is happening now for these streams. I am going to get the functionality working first then I'm going to add some spice by getting it to update the stream as it happens.

What I am hopefully going to end up with is something similar to the live Twitter feed on the econsultancy or twitpipe websites, displayed in a block.

What I am going to need to do for this is to make use of the twitter search service to pull in the rss, format it, and display it as a block in the site's layout.

If you have a play with the search twitter function on the site you notice that the results are output as an RSS feed, which is excellent news for this project, because it means I just need to access that feed and format the results.

This is the kind of thing I want it to end up like:

Lets get on with the module

In Drupal, modules have their own folder that contain all the files needed by the module. This keeps them all together and keeps things simple. Following the drupal standards the folder and main module files have the same name as the module, but it should be in machine readable format and by that I mean as lowercase and as one word. If your module has two words you can choose to run it into one word or put and underscore between the words. Create a folder in path: sites/all/modules/ and rename it to the name of you module.

As of Drupal 6.x, sites/all/modules is the preferred place for non-core modules (and sites/all/themes for non-core themes), since this places all site-specific files in the sites directory. This allows you to more easily update the core files and modules without erasing your customizations. Alternatively, if you have a multi-site Drupal installation and this module is for only one specific site, you can put it in sites/your-site-folder/modules.

There are a couple of required files that drupal needs to recognise a module and a few files that we can add in to create a complete module package.

The required files in the modulename folder are a and a modulename.module file. If you are going to distribute the module and need some things setting up (such as creating a database table or fields), you should include a modulename.install file as well.

We'll start by creating our .info file that will contain some basic information that drupal will use.

The .info (read dot info) file is a INI file, a simple file type, more of which can be found here

The .info file has a format to follow and some required information that is required. The has the following options:

;$Id$ // For Drupals CVS (Concurrent Version System) Server
name = Module name //Required. The standard is to have only the first letter only capitalised
description = Some information about the module //Required 255 character limit
package = Arbitrary grouping string // Optional. Where in the admin/build/modules page it will be listed
version = Version number // Optional incase you want to release .1, .2 etc versions
core = 6.x // Required. Tells drupal which version of core it should be to run this module
php = 5.1 // Optional. Whether php4 or php5 is required
dependencies[] = module // Optional. This tells drupal that our module requires this module to be active before it can run
dependencies[] = module // Multiple dependencies can be included by adding to the list.

The optional meta information can be left out if there is no information to give drupal. In the case of the package data if it is not assigned, it will simply be listed in the 'Other' section.

The Drupal Module developer's guide has some suggestions of appropriate items for the package field:

  • Audio
  • Bot
  • CCK
  • Chat
  • E-Commerce
  • Event
  • Feed Parser
  • Organic groups
  • Station
  • Video
  • Views
  • Voting (if it uses/requires VotingAPI)

The .info file is fairly straightforward so I won't go into more detail than the comments I've included above. The file for my module is going to look like this:

name = Live twitter feed
description = Provides a block that displays tweets live as they happen
package = Feed Parser
version = 
core = 6.x
php = 5.1

In the next part we'll look at the second file we need, the .module (read dot module) file and that's where all the good stuff happens


I actually loved this brilliant article. Please continue this awesome work.

I’ve recently started a site, and the info you provide on this web site has helped me tremendously. Thanks for all of your time & work.

After research a few of the blog posts on your website now, and I really like your way of blogging. I bookmarked it to my bookmark web site checklist and can be checking back soon. Pls try my web page as properly and let me know what you think.

I think the admin of this site is truly working hard
in support of his website, for the reason that here every stuff is quality based stuff.

Yeah, working really hard to keep comment spam clean of links etc.

Add new comment