tags:

views:

52

answers:

3

This code was working, but now it doesn't! Can anyone help?

$rss = simplexml_load_file("http://search.twitter.com/search.atomlang=en&q=charlton&rpp=100&page=1");
foreach($rss->entry as $item){
    $title = $item->title;
    print "$title";
}
A: 

Which part isn't working?

The first thing you can try is putting print_r($item) in your loop to see what's contained in $item.

The next thing you can try is var_dump($rss) (view page source) to see if the rss is actually loading properly.

What happens when you do that?

David
I tried print_r and it returned all the data, so then I removed it again to find the feed is now parsing again! Was it a server glitch or something? Any ideas why it worked, then didn't, then did again?
Steven
Either it simply didn't load properly the first time, or you changed something else while adding and removing the print_r that made it work. :)
David
+1  A: 

If you're working with twitter, you should consider using the Twitter.php class. It's very easy to use and intuitive

Here's an example of how I used Twitter.php in a module I wrote:

try {
    $username  = 'useername';
    $password  = 'password';
    $twi_user  = new Twitter($username,$password);

    $user_text = 'hello world';

    $twi_user->updateStatus($user_text);

  }
  catch (Exception $e) {
    echo $e->getMessage();

  }

OR Try and see if an error is caught:

try {

  $rss = simplexml_load_file("http://search.twitter.com/search.atom?lang=en&q=charlton&rpp=100&page=1");

  foreach($rss->entry as $item){

   $title = $item->title;

   print "$title";

  }

}
catch (Exception $e) {
  echo $e->getMessage()
}
DKinzer
A: 

The code should be working.

Depending on what you were doing, you probably ran into twitters "rate-limiting"..

http://apiwiki.twitter.com/Rate-limiting should be able to help you out in that case.

(Check the "Your application should recognize it is being rate-limited by the REST API if it receives begins to receive HTTP 400 response codes.[...]" section for a "how to check"/"what to do")

--

And now, after editing, your missing a "?" after search.atom ("..search.atom?lang=en..")

Kuchen