Armand Niculescu, BEng, MSM, is a 34 year old Art Director at Media Division. and he enjoys working with visual arts for film, web and print.

24 responses to “A Simple Twitter Search Parser with PHP”

  1. Jeremy

    Hey, great work. Thanks for writing this. Have you given any thought to how you would adapt this to parse feeds of geo searches, like ‘near:alabama within:50mi’ ? This returns a string like this: http://search.twitter.com/search.atom?geocode=40.75604%2C-73.986941%2C50.0mi&q=near%3Anyc+within%3A50mi which doesn’t work in the current configuration because of the geocode.

  2. Josh

    I love it, I just wish there were a way to specify which size of avatar you want to pull… As it is now, it’s pulling a 48×48 avatar but I need to pull a 44×44 instead.

    I tried using timthumb, but even after adding a1.twimg.com, a2.twimg.com, and a3.twimg.com to the list of remote sites in the timthumb script, it still won’t work.

    oh well.

  3. Jay

    Hi, this works wonderfully for normal search terms, but I’m having trouble getting tweets from a single user using the search operator “from:user” It returns a url like this:

    http://search.twitter.com/search.atom?q=from%3Anytimes

    I’m plugging in ‘from%3Anytimes’ as my search term, but I’m not getting any results. Am I doing something stupid?

  4. John

    great post!!

    Is there a way to get an array of found tweets, so that I can count() them? All I want is to output the number of found tweets against a search term.

  5. Jason

    I was leaning toward client side javascript/Ajax to accomplish this, but I love what you have done with PHP instead. This is really clean code. Do I have permission to reuse and style it to for use with CSS? Also, Is there anyway to increase the tweet posts to last more than 2 days? I would like to see tweets on a #hashtag or keyword last for more than a week. Excellent work!

  6. Jason

    Thank you Armand! I increased the number of tweets to 50:

    getTweets(‘ifest’, 50);
    ?>

    However, it appears that after 48 hours the tweets begin to drop off the list. Here is the example I created: http://jhaag.us/twitter_class/ for the search term “ifest”. There were 8 tweets on there yesterday and today there are only two.

  7. Waqqas Hanafi

    Armand, having more than 15 results will be very useful. Please consider adding it as a feature in your class.

  8. Anthony

    I’ve been looking for something like this for a while. Thanks a lot!
    Your tutorial was very useful for me.
    I am also kind of interested in more than 15 posts, but I may try integrating this with a MySql database so that I can store tweets and display them as needed.
    Thanks again!

  9. Anthony

    Actually, if possible I would love to know how to style the “Twitter Search Term”. I can style everything else with CSS, but I can’t seem to find a way to style only the search term.

  10. Anthony

    Thank you so much!!!!!! I was trying to use php to style it! This is much easier :)

  11. Tommy

    Love your work…

    I’ve got as far as reloading a div with AJAX and having that ‘div class = the time’ – any tips on the PHP for only fetching a tweet newer than the timestamp? Would appreciate any help :)

  12. Madhusanka

    Very simple and really helpful !!! Thanx lot Armand
    keep it up this good work… :-)

  13. Madhusanka

    hi, As you said, can you provide that mechanism in details(may be a new post) to get all the tweets for a search or geocode api rather than limiting it to 15. Really urgent !!!
    Thanks again…

  14. Jeremy

    This appears to have been affected by changes to the Twitter API. I got it working again once I removed lang=en from line 8, so it just reads:

    $this->searchURL = ‘http://search.twitter.com/search.atom?&q=’;

  15. talha

    Hi,
    awesome tutorial. is there a way to get the total amount of tweets in a day for a keyword?
    Thanks

  16. Manoj Solanki

    Thanks for this example code…..