Add RSS/Atom Feed of Multiple Twitter Accounts to your Website.

Add a Feed of multiple Twitter acounts to your websiteCreate an RSS/Atom Feed for your website that is populated by the tweets of multiple Twitter accounts and / or multiple search words. Twitter Search returns its results, the most recent tweets, in the form of an Atom feed. The steps in this article will help you pull those tweets and make them part of the feed for your own website.

Note: the code here is written in PHP. Your web server will have to be equiped to run this code (typically an Apache webserver running on Linux).

1. Create a folder on your website called "feed".

2. Copy these three files into the new directory.

3. Important! Make sure the two files feed_cache.xml and feed_cache_laststamp.txt are set at writeable. This is done on the file system on your web server. Different hosting companies handle it differently, but you probably have a place where you can edit a file's properties. Some FTP clients also can do this. I use FireFTP, a plugin FTP client for the Firefox browser. To make a file writeable, I just have to right-click on the file, choose "properties", and check off all the boxes that say "write".

These files are used as a very simple caching system. Normally, I use other 3rd party caching modules available on my Apache web servers. However, not all hosting companies offer the same methods, so we are creating a very basic one here. As you may know, Twitter limits the number of calls you can make to its site every hour. If we did not cache the results for your RSS/Atom feed, every user that hits your website would make a call to Twitter on behalf of your server. You would very quickly call out to Twitter more than your hourly allotment. In this caching method, we are simply storing the feed in a local file, to be refreshed every few minutes. Your server would then only call Twitter just a few times an hour, much below any limits. It will also make the feed much faster.

4. Update the parameters in the feed.php file. Open the feed.php file in a text editor. You will change the values in the following variables: $keywords, $cache_time, and $title.

$keywords :: Add Twitter Account names (including the @) and search words you would like to be contained in the feed. Each word is to be surround by quotes (single or double), and separated by commas.

example code (two Twitter accounts):
$keywords = Array ('@CarpData', '@LocalChirps');

another example (a twitter account and two search words):
$keywords = Array ('@eoktown', 'entrepreneur', 'entrepreneurs');

another example (hash tags):
$keywords = Array ('#PubNight', '#eokmeeting');

Be careful not to put too many commas in the list. This is a very common mistake.
THIS IS WRONG WAY: $keywords = Array ('#PubNight', '#eokmeeting', );
(Notice the extra comma at the end, right before the closing parenthesis. This will cause an error.)

$cache_time :: the number of seconds to hold the cache. 600 seconds (10 minutes) is a good time. You should not go less than 60 seconds, Twitter will not be refreshing the search results that fast anyway.

$title :: Change this to a short description of your website. Otherwise, Twitter's title of the search criterial will be displayed.

5. Last thing, you want to tell the world that your RSS/Atom Feed exists on your website. Open your main home page in a text editor (usually a file named index.html). Add the following line in the <head> section:

<link rel="alternate" type="application/atom+xml" href="/feed/feed.php" title="Carp Data Feed" >
(change the title to whatever you like)

When complete, your browser should display the add RSS to your website symbol in the address bar of your home page.

That's it. Let me know if you have any questions.

Views: 570


You need to be a member of Entrepreneurs of Knoxville to add comments!

Join Entrepreneurs of Knoxville


© 2019   Created by Leonard Knight.   Powered by

Badges  |  Report an Issue  |  Terms of Service