We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Taking an RSS feed from Twitter
Page Index Toggle Pages: 1
Taking an RSS feed from Twitter (Read 2476 times)
Taking an RSS feed from Twitter
Apr 22nd, 2009, 8:05am
 
I have managed to modify the example of taking a simple rss feed from the internet to take its feed from Twitter. I sometimes works but most of the time doesn't. It comes up with a NULLPOINTEREXCEPTION error. Does anyone know why this is. IT works perfectly well with any other feed that I have tried, it is just Twitter that is unpredictable.

Cheers,

Mike
Re: Taking an RSS feed from Twitter
Reply #1 - Apr 22nd, 2009, 8:12am
 
So from what I understand you are using an RSS feed to grab data from a Twitter account?

A null pointer exception is what happens when you are trying to look at something that doesn't exist (sort of). The first thing I always do is check that everything I'm assigning values to, from the RSS feed, is actually getting those required values. If you try and retrieve the value at a later date from the variable and it doesn't have the value in there then hey presto, null pointer exception.

I hope this helps...
Re: Taking an RSS feed from Twitter
Reply #2 - Apr 22nd, 2009, 12:31pm
 
It only seems to stop working if a twitter post of about 140 characters is sent, it seems to handle the smaller posts ok. Once it comes up with the error I leave it for about an hour and then re-run the program and it works ok until another big post comes its way. Here is the code I am using, sorry for its 'hacky' nature, I am quite new to processing and am just sticking existing examples together and tweaking them.....

Its not allowing me to post weblinks so the rss feed address is where the "RSS FEED GOES HERE" part is.


import processing.xml.*;
// Array to store titles
String[] titles;

PFont font;
void setup() {
 size (800, 150);
 background(0);
 noStroke();
 
 // Setup font
 font = loadFont("CourierNew36.vlw");
 textFont(font, 24);
 
 // Load RSS feed
 String url = "RSS FEED GOES HERE";
 XMLElement rss = new XMLElement(this, url);
 // Get title of each element
 XMLElement[] titleXMLElements = rss.getChildren("channel/item/title");
 titles = new String[titleXMLElements.length];
 for (int i = 0; i < titleXMLElements.length; i++) {
   String title = titleXMLElements[i].getContent();
   // Store title in array for later use
   titles[i] = title;
 }
}
void draw() {
   background(255);
   fill(255,0,0);
   text(titles[0], 20, 30);
     String url = "RSS FEED GOES HERE";
 XMLElement rss = new XMLElement(this, url);
 // Get title of each element
 XMLElement[] titleXMLElements = rss.getChildren("channel/item/title");
 titles = new String[titleXMLElements.length];
 for (int i = 0; i < titleXMLElements.length; i++) {
   String title = titleXMLElements[i].getContent();
   // Store title in array for later use
   titles[i] = title;
 }  
}

All suggestions are welcome,

Mike
Re: Taking an RSS feed from Twitter
Reply #3 - Apr 23rd, 2009, 8:01am
 
I have now tried to use the Twitter4J API, I thought I had it cracked, but again it seems to be unpredictable, the minute I get it working it stops again, this time with no errors, it just doesnt reed anything from twitter.
Heres the code I am now using.....


int startingPoint = 0;
Twitter twitter;
int myFriendsCount;
User[] friends;
String username = "username";
String password = "password";
twitter = new Twitter(username,password);
String myTimeline;
PFont font;
 // Setup font
 font = loadFont("CourierNew36.vlw");
 textFont(font, 18);


try
{
java.util.List statuses = twitter.getUserTimeline();
 //List statuses = twitter.getUserTimeline();

    Status status = (Status)statuses.get(0);
         println(status.getUser().getName() + ":" +
                                 status.getText());
           

}
catch( TwitterException e)
{
// catch error here
}


size (500,150);
background (0);
text("hello", 20, 15);
loop();


Does anyone have any ideas?

Mike
Re: Taking an RSS feed from Twitter
Reply #4 - Jun 5th, 2009, 10:50am
 
I just wanted to update this thread for anyone searching for this information. I've been working a lot with Twitter lately, and I've discovered there is a rate limit involved in sending HTTP Get requests to Twitter. If you exceed your amount, your IP will be blocked for a while, hence the one hour wait mentioned above. This block will result in the HTTP 400 response, and this will trigger the NullPointerException in Processing.  

You can find some useful information on Twitter rate limits here:
http://apiwiki.twitter.com/Rate-limiting
Page Index Toggle Pages: 1