Twitterfeed

Twitterfeed (http://twitterfeed.com) is a service that publishes tweets on your behalf (that is, using your Twitter account) from feeds (for instance, from your blog) you provide to it. This is cool but the really nice thing is that its name paints a more restrictive picture than is reality: Twitterfeed can also publish updates on your behalf to Facebook and LinkedIn. And each of these is optional so you can publish to any or all of Twitter, Facebook, and LinkedIn.

I've chosen to set up Twitterfeed to publish to all of Twitter, Facebook, and LinkedIn. So that means that a notification about this, my first blog post written since I began using Twitterfeed, should get published out to my Twitter account, my Facebook account, and my LinkedIn account.

Cool, huh? How do you get updates about your blog posts out to Twitter, Facebook, and LinkedIn?

Creating an RSS Feed Using <cffeed> with a Structure

The Adobe ColdFusion 8 documentation has a ton of great information on the <cffeed> tag, including a nice example of how to create an RSS feed using <cffeed> with a structure. There's no need to rehash that information, but I do want to expound on it to explain how you specify categories and enclosures as well as guid info for an item in a feed because I think specifying these for an item in a feed is a little tricky. So what I'm going to do is take the above example as a starting point, adding in the code that demonstrates how to specify categories and enclosures and guid info for an item and removing some non-essential code so as not to overly complicate things:

<cfsetting showdebugoutput="no">

<cfscript>
   /* Create the feed data structure and add the metadata. */
   myStruct = StructNew();
   myStruct.link = "http://" & CGI.HTTP_HOST & CGI.SCRIPT_NAME;
   myStruct.title = "My RSS Feed";
   myStruct.description = "A demonstration of <cffeed>";
   myStruct.pubDate = Now();
   myStruct.version = "rss_2.0";
   
   /* Add the feed items. A more sophisticated application would use dynamic variables
      and support varying numbers of items. */

   myStruct.item = ArrayNew(1);
   myStruct.item[1] = StructNew();
   myStruct.item[1].category = ArrayNew(1);
   myStruct.item[1].category[1] = StructNew();
   myStruct.item[1].category[1].value = "Cat1";
   myStruct.item[1].enclosure = ArrayNew(1);
   myStruct.item[1].enclosure[1] = StructNew();
   myStruct.item[1].enclosure[1].url = "http://" & CGI.HTTP_HOST & "enc/myenclosure.mp3";
   myStruct.item[1].enclosure[1].length = 1212;
   myStruct.item[1].enclosure[1].type = "audio/mp3";
   myStruct.item[1].description = StructNew();
   myStruct.item[1].description.value = "The first item in the feed";
   myStruct.item[1].guid = StructNew();
   myStruct.item[1].guid.isPermaLink = "Yes";
   myStruct.item[1].guid.value = "http://" & CGI.HTTP_HOST;
   myStruct.item[1].title = "Item 1";
   myStruct.item[2] = StructNew();
   myStruct.item[2].category = ArrayNew(1);
   myStruct.item[2].category[1] = StructNew();
   myStruct.item[2].category[1].value = "Cat1";
   myStruct.item[2].category[2] = StructNew();
   myStruct.item[2].category[2].value = "Cat2";
   myStruct.item[2].description = StructNew();
   myStruct.item[2].description.value = "The second item in the feed";
   myStruct.item[2].guid = StructNew();
   myStruct.item[2].guid.isPermaLink = "Yes";
   myStruct.item[2].guid.value = "http://" & CGI.HTTP_HOST;
   myStruct.item[2].title = "Item 2";
</cfscript>

<cffeed action = "create"
   name = "#myStruct#"
   xmlVar = "myXML">


<cfcontent type="text/xml" reset="true"><cfoutput>#myXML#</cfoutput>

Please note the following:

  • The code was specifically written without external dependencies so that it will work on any ColdFusion 8 installation.
  • <cfsetting showdebugoutput="no"> can be a lifesaver when working with <cffeed>--I was tearing my hair out for a bit until I had that head-slapping moment when it dawned on me why I kept being told by the browser that the feed was invalid.
  • I consider it good coding practice to always scope variables, even those in the Variables scope. The only reason the above code doesn't use scoped variables is to keep it as similar as possible to the example code referenced at the top of this post.
  • If you're looking for information on the metadata properties for the feed itself, see Ray Camden's blog post on the subject.

Redirecting RSS feeds

After my last post (about my blog's move) generated a whopping 3 views (possibly all by me!), I began to believe that my suspicions that RSS readers may not like HTTP 302 redirects might be well-founded. So I checked out Full As a Goog and sure enough, it wasn't showing my new post some many hours after I posted it.

So I did a little digging into the matter of redirecting RSS feeds and I found that an HTTP 302 redirect (which is what I was using) should temporarily redirect the feed. I'm not sure why that wasn't working.

But it doesn't really matter because I don't truly want a temporary redirect, I want a permanent redirect. For that it appears there are two choices: use an HTTP 301 redirect or use an XML level redirect (further info on both is given at the above link). It is possible to generate either using ColdFusion (for the former, you would use <cfheader> and for the latter you just put the appropriate XML into your RSS XML output). The latter struck me as a more interesting approach so that is the one I am now using.

Does it work? I'm not sure--you tell me! If you were consuming the feed from its old location at http://www.joshuaadams.com/blog and your reader is now consuming the feed from its new location at http://blog.joshuaadams.com then yep, it worked for you. But if you're still showing the old feed, then no, it isn't working for you (although that then begs the question of how you ended up here). Comments letting me know if it worked for you are appreciated; comments letting me know it didn't work for you are even more appreciated.

BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner