首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Twitter调用间歇性失败

Twitter调用间歇性失败
EN

Stack Overflow用户
提问于 2010-07-10 21:28:11
回答 4查看 848关注 0票数 0

我使用PHP来显示用户的最新推文。这是Wordpress的。这在大多数情况下都是可行的--但有时,我会遇到这样的错误:

file_get_contents(时间线/[用户名].json)函数.文件-获取内容:打开流失败: HTTP请求失败!HTTP/1.1 400第47行./twitter.php中的不良请求

我绝对肯定我不会超过Twitter API的限制,因为即使我的缓存代码有缺陷,也没有其他人能看到--它是本地托管的--而且我不可能在一小时内浏览150次。我已经测试了用户名和数据库条目确实被检索了。这是我的密码:

代码语言:javascript
运行
复制
<?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 } ?>

我真的很想在这方面提供一些帮助。我完全感到困惑。

EN

Stack Overflow用户

发布于 2010-07-10 21:40:04

你多久打一次电话给这个函数?如果我没记错的话,twitter最近将每小时的最高通话量从150~ 75次更改为每小时75次。您可能需要缓存结果,以避免耗尽您的零花钱。

看这个斯拉什多故事:Twitter节流第三方应用程序

票数 1
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3220899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档