我使用PHP来显示用户的最新推文。这是Wordpress的。这在大多数情况下都是可行的--但有时,我会遇到这样的错误:
file_get_contents(时间线/[用户名].json)函数.文件-获取内容:打开流失败: HTTP请求失败!HTTP/1.1 400第47行./twitter.php中的不良请求
我绝对肯定我不会超过Twitter API的限制,因为即使我的缓存代码有缺陷,也没有其他人能看到--它是本地托管的--而且我不可能在一小时内浏览150次。我已经测试了用户名和数据库条目确实被检索了。这是我的密码:
<?php
function twitter($username) {
$tweet = '';
echo $username;
if (!get_option('twitter_last_updated')) {
$format='json';
$tweet_raw=file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}");
$tweet = json_decode($tweet_raw);
add_option('twitter_last_updated', time(), "", "yes");
add_option('twitter_last_updated_author', $username, "", "yes");
add_option('twitter_last_updated_data', $tweet_raw, "", "yes");
} elseif (time() - get_option('twitter_last_updated') > 30 || get_option('twitter_last_updated_author') != $username) {
$format='json';
$tweet_raw=file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}");
$tweet = json_decode($tweet_raw);
update_option('twitter_last_updated', time());
update_option('twitter_last_updated_author', $username);
update_option('twitter_last_updated_data', $tweet_raw);
} else {
$tweet = json_decode(get_option('twitter_last_updated_data'));
} ?>
<!-- display the tweet -->
<?php } ?>我真的很想在这方面提供一些帮助。我完全感到困惑。
发布于 2010-07-10 21:40:04
你多久打一次电话给这个函数?如果我没记错的话,twitter最近将每小时的最高通话量从150~ 75次更改为每小时75次。您可能需要缓存结果,以避免耗尽您的零花钱。
看这个斯拉什多故事:Twitter节流第三方应用程序
https://stackoverflow.com/questions/3220899
复制相似问题