33 responses to “Integrate Twitter Into Your Web Site Using PHP”

  1. Jesse

    Awesome work.. this is exactly what I needed. Also here’s some additional code for anyone wanting to output a bit more:

    <?php foreach ($feed as $item): ?>
       <h2><a href="<?=$item['link']?>"><?=date('F j, Y - g:ia', strtotime($item['date']))?></a></h2>
           <p><?=linkify_tweet($item['desc'])?></p>
    <?php endforeach; ?>
    

    Basically I cleaned up the date output with the strtotime() function. To format the date to your liking you should refer to PHP date() formats

    Great script man… would be great to expand this a bit more for less savvy php users.

    Is it just me or is the Title and Desc in the RSS the same data?

  2. flapane

    Hi!
    Any way to include replies?
    Thanks!

  3. flapane

    Thanks.
    FYI I’ve just made it building a Yahoo pipe from scratch, see the result in my homepage (lower right corner, LAST TWEETS), and tell me what do you think.

  4. Markus Steiger

    Thanks !!
    I’m use this with “jQuery .load()”
    Idea …

  5. Just Web Design

    Just what I was looking for! Worked a treat!
    Also altered it slightly to bring in our Tumblr blog from the RSS feed.

  6. Peter

    This is awesome, been browsing for days trying to find something that actually works.

    Just one question based on Jesse’s comment, any idea how to output the time as “time ago” rather than just output the exact date from the rss file?

  7. Peter

    Thanks for the reply Dimas,

    Seems that it keeps outputing 705 days for all tweets :S not sure where i’ve gone wrong.

    I’m not really that experienced in PHP, seems pretty straight forward though when using human_time_diff on comments or posts from within WP but i can’t seem to figure out how to implement it into your twitter code.

    Any help?

  8. Peter

    It’s actually outputing the following: “14839 days ago” for each tweet.

    I modified the date in the array as you suggested above and then used the following to print the time:

     echo human_time_diff(('date'), current_time('timestamp')) . ' ago';
  9. Peter

    That did the trick! Thanks again Dimas.

  10. Browntree Design

    Nice, worked well used it to pull other rss feeds too thanks.

  11. Dee

    thanks for the code, exactly what I needed!

  12. Mark

    Thanks for this post Dimas, I just set it up myself and it works beautifully!

  13. Bastian

    This code is just what I was looking for. But it seems like Twitter doesn’t allow RSS-Feeds anymore. Do you know an alternative way?

  14. Pendo

    I get the following errors –
    Warning: file_put_contents(tmp-1315951485.xml): failed to open stream: Permission denied in C:\web\includes\twitter.php on line 26 Warning: file_put_contents(tmp-info.txt): failed to open stream: Permission denied in C:\web\includes\twitter.php on line 42

    However, the tweets come out ok. I’m assuming that means it can’t create a cache file. I’m on win 2008 IIS7. I’ve used php cgi-wrap for linux in the past to get around permissions issues….Not sure what to do with Windows…. Thanks for the great tutorial!

  15. Edd

    Is there a way of using php to integrate a specific list I’ve got set up on my twitter account so that users on my website will only view tweets from accounts in a specific list?

  16. Brent

    Hi,

    I’ve modified it slightly but it is working great. How would you go about cleaning up old cache files? I think you really only need to store the one cache file, right?

  17. crashfellow

    Hoping you have a solution. If you delete the cache files, it will spit an error msg. You then refresh and the tweets show up. The cache files also do exist at that point.

    So i think there’s a bug in the script where the first time it runs, it has to create the files, but creates them after it loads. So because of this it errors out.

    Any solution for this??

  18. Brent

    Has the solution changed since my comment? If not, it hasn’t been cleaning up for me. Perhaps I implemented it incorrectly …

Leave a Reply