1

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

<?php
    $username='myUsername';
    $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.

Ryan
  • 767
  • 3
  • 9
  • 31
  • (tip) [How do I enable error reporting](http://stackoverflow.com/questions/6575482/php-how-do-i-enable-error-reporting) – Gordon Feb 15 '13 at 08:20

1 Answers1

0

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 check the question I've posted here at stackoverflow as a reference to your problem:

Display latest Twitter Feed "date created" using tmhOAuth and PHP

It already have the codes how to access the common information needed to be retrieved in Twitter.

Community
  • 1
  • 1
thedevgypsy
  • 79
  • 1
  • 13