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!