views:

23

answers:

1

Hello!

What is the simplest way to display this kind of feed? I've heard you can do this with Yahoo pipes, but does Twitter directly support this?

Thanks!

A: 

http://search.twitter.com/search?q=%23weloveyouss501

there is your hash tag... see at the right there is an rss feed of this query:

http://search.twitter.com/search.atom?q=%23weloveyouss501

brilliant - now all you need is TouchXML and this function:

-(void)getRSSFeed:(NSString *)XMLString {

    blogEntries = [[[NSMutableArray alloc] init] autorelease]; // blogEntries in header

    NSError *theError;
    CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithXMLString:XMLString options:0 error:&theError] autorelease];

    if(theError){
        NSLog(@"An error");
    }

    NSArray *resultNodes = NULL;
    resultNodes = [rssParser nodesForXPath:@"//item" error:nil];

    for (CXMLElement *resultElement in resultNodes) {
        NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init];

        int counter;
        for(counter = 0; counter < [resultElement childCount]; counter++) {

            [blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
        }
        [blogEntries addObject:[blogItem copy]]; // blog entries set in header
    }

}

if you output blogEntries you will see all the entries. :) Now you can get at them easily. :)

Thomas Clayson
You know that `[[[NSMutableArray alloc] init] autorelease]` is the same as `[NSMutableArray array]` right?
St3fan
Also, you leak memory when adding the retained copy `blogItem`. Doing `blogItem = [NSMutableDictionary dictionary]` and then later `[blogEntries addObject: blogItem]` will solve that.
St3fan
ah, fair enough mate - I didn't write it... can't remember where I got it from now, although its somewhat modified, so might be my fault. :/ Ah, thanks for the heads up.
Thomas Clayson
Thanks, Thomas Clayson. So, to get a real-time feed, I would: 1) do an HTTP get on the atom url 2) pass the result into getRSSFeed 3) display results 4) run timer and repeat for real-time ?
Jacko
I would make a custom class that does an asynchronous url request (NSURLConnection) and fetches those results. Then I would run a timer, as you say, to run that class over and over again. Then in my custom class I would have a delegate method that gets called once the script has completed and have the method `reloadData` the main table view (if thats how you're doing it). :) hope this helps
Thomas Clayson
cool. Thanks for your help, Thomas.
Jacko