我有這個代碼,根據計數值(目前設置爲5)創建一個鳴叫數組,但是,當我嘗試顯示推文時,我什麼也沒有得到,但數組重複了5次(而不是實際的推文),任何人都可以幫我解決我做錯了什麼?順便說一下,如果我將計數更改爲1,然後僅回顯變量$ tweet,我就可以正確顯示最新的推文顯示。PHP調用超過1 Tweet
function get_tweet() {
require 'parts/tmhOAuth.php';
require 'parts/tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'taken out for security purposes',
'consumer_secret' => 'taken out for security purposes',
'user_token' => 'taken out for security purposes',
'user_secret' => 'taken out for security purposes',
'curl_ssl_verifypeer' => false
));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array(
'screen_name' => 'designernewsbot',
'count' => '5'));
$response = $tmhOAuth->response['response'];
$tweets = json_decode($response, true);
// This is to create links in my webpage if links are specified in the tweet
$tweet = $tweets[0]['text'];
$tweet = preg_replace("/([\w]+\:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/", "<a target=\"_blank\" href=\"$1\">$1</a>", $tweet);
$tweet = preg_replace("/#([A-Za-z0-9\/\.]*)/", "<a target=\"_new\" href=\"http://twitter.com/search?q=$1\">#$1</a>", $tweet);
$tweet = preg_replace("/@([A-Za-z0-9\/\.]*)/", "<a href=\"http://www.twitter.com/$1\">@$1</a>", $tweet);
foreach($tweets as $tweet):
echo $tweet;
endforeach;
}
什麼'print_r($ tweets);'輸出? –
您是否嘗試過var_dump $ tweet並查看裏面有什麼? –
@DavidLandes我剛剛在foreach循環中嘗試了這一點,然後找回似乎是大量數據的地獄,而不僅僅是推文,而是關於執行推文發送的用戶的數據等。不知道我在做什麼是誠實...任何想法? – egr103