0
所有, 我有以下代碼獲取Twitter的狀態,並顯示它給用戶:Twitter使用API獲取用戶狀態值,是否有限制?
if(! $tweet) {
//$format = 'json';
//$contents = file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}", 0, $context);
//$contents = file_get_contents(" https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_many}", 0, $context);
$url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_many}";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($curl);
curl_close($curl);
if (! empty($contents)) {
// Decode it.
$tweet = json_decode($contents);
// Cache it for next time.
//set_transient($id.'-'.$username, $tweet, 60*60*3); // 3 hour cache
}
}
// Check to make sure we have a tweet and display it.
if (is_array($tweet) && isset($tweet[0]->id_str)) {
do_action('themeblvd_twitter_slider', $tweet, $options, $username, $slider_id);
} else {
$output = '<span class="tweet-icon '.$options['icon'].'"></span>';
$output .= 'We experienced an error with Twitter! Please check back soon for our reviews!';
}
return $output;
所以基本上我想確定我是否已經獲取了一些微博,如果沒有去取出它們,然後將它們傳回到下面的循環以將它們顯示給用戶。
<?php
foreach($tweet as $t){
?>
<li class="slide tight <?php echo $classes; ?>">
<div class="slide-body">
<div class="grid-protection">
<?php
echo '<span class="tweet-icon '.$options['icon'].'"></span>';
echo '<a href="http://twitter.com/'.$username.'/status/'.$t->id_str.'" target="_blank">';
echo $t->text;
echo '</a>';
?>
</div><!-- .grid-protection (end) -->
</div><!-- .slide-body (end) -->
</li>
<?php
}
?>
出於某種原因,我收到錯誤消息,說他們無法顯示。如果我將限制保持爲10,則它顯示的相當一致,沒有錯誤。如果我將限制增加到50或85,我會收到錯誤消息,指出twitter有問題。 API最近有變化嗎?他們有新的限制嗎?關於爲什麼我無法顯示85條推文的任何想法?
感謝advace!