Отобразить последнюю ленту новостей Twitter «дата создана» с использованием tmhOAuth и PHP

Поскольку Twitter API v1 «вышел на пенсию», я в конечном итоге искал новый способ отображения последней ленты Twitter с использованием PHP, на которой я нашел «themattharris / tmhOAuth» (библиотека OAuth 1.0A, написанная на PHP), которую можно загрузить в GitHub:

  • https://github.com/themattharris/tmhOAuth

Я проверил google и нашел две полезные ссылки в использовании указанной библиотеки:

  • http://www.simplistips.com/tips/advanced/twitter-oauth-using-php-api-version-1-0-1-1/
  • Использование PHP и нового API Twitter

Благодаря следующим ссылкам, я могу отображать последний твиттер. Вот мои коды в 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); 

Но я не могу показать дату, может ли кто-нибудь мне помочь? Я пробовал "foreach"

 foreach ($twitFeed as $item) { $feedDate = $item->created_at; } 

Но это дает мне «Уведомление: попытка получить свойство не-объекта в http: localhost / try.php on line xx», который указывает на «$ feedDate = $ item-> created_at;»

Я все еще новичок в Twitter API … Пожалуйста, помогите …

Оппс, только что получил решение в моей дилемме, я все равно передам код кому угодно …

 <?php $twitter_id = "your_twitter_id"; $no_of_Feeds = 1; require "class/tmhOAuth/tmhOAuth.php"; require "class/tmhOAuth/tmhUtilities.php"; $tmhOAuth = new tmhOAuth(array( 'consumer_key' => 'your_consumer_key', 'consumer_secret' => 'your_consumer_secret', 'user_token' => 'your_user_token', 'user_secret' => 'your_user_secret', )); $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array( 'screen_name' => $twitter_id, 'count' => $no_of_Feeds)); $response = $tmhOAuth->response['response']; $twitFeed = json_decode($response, true); foreach ($twitFeed as $latestFeed) { $feedDate = $latestFeed["created_at"]; $postedLast = explode(" ", $feedDate); $feedCreatedAt = $postedLast[0]." - ".$postedLast[1]." ".$postedLast[2].", ".$postedLast[5]; $feedMsg = $latestFeed["text"]; $feedMsg = preg_replace("/([\w]+\:\/\/[\w-?&;#~=.\/\@]+[\w\/])/", "<a target="_blank" href="$1">$1</a>", $feedMsg); $feedMsg = preg_replace("/#([A-Za-z0-9\/.]*)/", "<a target="_new" href="http://twitter.com/search?q=$1">#$1</a>", $feedMsg); $feedMsg = preg_replace("/@([A-Za-z0-9\/.]*)/", "<a href="http://www.twitter.com/$1">@$1</a>", $feedMsg); } ?> <a href="https://twitter.com/<?php echo $twitter_id; ?>" target="_blank">@<?php echo $twitter_id; ?></a> <b>said:</b> <?php echo $feedMsg; ?> <b>last</b> <?php echo $feedCreatedAt; ?><br /> 

Просто заменил «$ item-> created_at» на «$ lastFeed [" created_at "]".