Since Twitter API v1 "retired", I ended up looking for a new way to display the latest Twitter Feed using PHP, which I found "themattharris / tmhOAuth" (OAuth 1.0A library written in PHP), which can be downloaded at GitHub:
I checked google and found two useful links in using the said library:
- http://www.simplistips.com/tips/advanced/twitter-oauth-using-php-api-version-1-0-1-1/
- Using PHP and the new Twitter API
Thanks to the following links, I'm able to display the latest twitter feed. Here are my codes in PHP:
require '../class/tmhOAuth/tmhOAuth.php';
require '../class/tmhOAuth/tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'xxx',
'consumer_secret' => 'xxx',
'user_token' => 'xxx',
'user_secret' => 'xxx',
));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array(
'screen_name' => 'xxx',
'count' => '1'));
$response = $tmhOAuth->response['response'];
$twitFeed = json_decode($response, true);
$twitFeed = $twitFeed[0]['text'];
$twitFeed = preg_replace("/([\w]+\:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/", "<a target=\"_blank\" href=\"$1\">$1</a>", $twitFeed);
$twitFeed = preg_replace("/#([A-Za-z0-9\/\.]*)/", "<a target=\"_new\" href=\"http://twitter.com/search?q=$1\">#$1</a>", $twitFeed);
$twitFeed = preg_replace("/@([A-Za-z0-9\/\.]*)/", "<a href=\"http://www.twitter.com/$1\">@$1</a>", $twitFeed);
echo($twitFeed);
But I can’t seem to display the date, can anyone help me? I've tried "foreach"
foreach ($twitFeed as $item) {
$feedDate = $item->created_at;
}
But it's giving me "Notice: Trying to get property of non-object in http:localhost/try.php on line xx", which is pointing in the "$feedDate = $item->created_at;"
I'm still kinda new with Twitter API... Please help...
Opps, just got the solution in my dilemma, I'll be sharing the code to anyone anyways...
Just replaced the "$item->created_at" to "$latestFeed["created_at"]".