Take the 2-minute tour ×

I am currently using the following code to retrieve the latest tweet from my Twitter feed:

    $format = 'json';
    $tweet = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}"));
    $latestTweet = htmlentities($tweet[0]->text, ENT_QUOTES);
    $latestTweet = preg_replace('/http:\/\/([a-z0-9_\.\-\+\&\!\#\~\/\,]+)/i', '<a href="http://$1" target="_blank">http://$1</a>', $latestTweet);
    $latestTweet = preg_replace('/@([a-z0-9_]+)/i', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $latestTweet);
    echo '<p class="inset white">'.$latestTweet.'</p>';

On MAMP, this works perfectly, however on my live site, I get nothing, not even a server side error message. I read on a similar post that this may be something to do with allow_url_fopen = On not being set in php.ini, but setting that appears to have made no difference.

Not withstanding the fact that Twitter may have changed their policy on usage of the API (which I don't believe they have), then I'm lost as to what could be the problem.

share|improve this question
(tip) How do I enable error reporting –  Gordon Feb 15 '13 at 8:20
add comment

1 Answer

I'm using the same approach before, but unfortunately, it's using Twitter API v1 and v1 is no longer available (check https://dev.twitter.com/blog/api-v1-retirement-final-dates for more details). You need to have the OAuth consumer and user access now. GitHub themattharris' tmhOAuth library is handy for displaying Twitter feed.

You may use the solution posted in this link: http://profabbynucup.tumblr.com/post/53031776012/display-your-latest-twitter-feed-using-php-and-oauth

share|improve this answer
Welcome to Stack Overflow. Please summarise the link in your answer; that way, if the link goes stale the answer won't be completely useless. –  michaelb958 Jun 15 '13 at 16:52
add comment

Your Answer


