Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Gadgets and Digital Lifestyle

  • Print
  • + Share This
Like this article? We recommend Constructing the Twitter Widget

Constructing the Twitter Widget

Once the feed has been retrieved, it's returned as a response to the Tweeter object. Tweeter.checkReadyState determines the status of the readyState. Once the status of the readyState has reached 4 or has completed processing, the XML for the Twitter feed is sent to the Tweeter.onResponse method.

Now it's finally time to create the widget, but first we need to parse the tweets. The Twitter feed is a standard RSS file, with titles, links, descriptions, dates, and so on for each tweet. We need to access the item elements in the feed, which contain each tweet, and then we loop through, adding the values to the appropriate array for later use. (Some of these values are not used in the example, but can easily be accessed and added to the widget.)

Now that we have arrays containing the values for each tweet, we can build an HTML list based on the number of tweets set in the Tweeter.tweetCount property (one of the optional properties set in the HTML file in Listing 1). In this case, the Tweeter.tweetCount property is set to 3; therefore, the three latest tweets will be added to the list. After the list has been constructed, we refer to the Tweeter.location that we determined prior to making the request, and add the widget to the appropriate location in the page.

  • + Share This
  • 🔖 Save To Your Account