0 Replies - 1469 Views - Last Post: 12 December 2009 - 12:12 PM

#1 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Twitter Public Statuses

Posted 12 December 2009 - 12:12 PM

Description: Uses Twitter API to receive the last 20 public statuses posted. Requires no authentication.
require 'rss' 
#to parse RSS
require 'open-uri'
#to fetch the data
#the Twitter API updates this RSS feed only once per minute, so don't bother calling this repeatedly
def twitPubStatus() #yes, it's a clumsy name for a function. rename it to whatever
	statusFeed = 'http://twitter.com/statuses/public_timeline.rss'
	rawRSS = ""
	open(statusFeed) do |f|
		rawRSS =  f.read
	tweets = RSS::Parser.parse(rawRSS, false)
	#parse the RSS
	retVal = []
	#returns an array to make it easier to work with the data later
	tweets.items.each do |f|
		retVal << "#{f.description}n"
		#f.description in this case holds both the user name and the tweet
		#you could add the time posted to this, but since this will always return the last
		#20 of the minute, it is a little pointless
	return retVal

a = twitPubStatus()

puts a #this prints the entire array at once instead of one status at a time

Is This A Good Question/Topic? 0
  • +

Page 1 of 1