PHP を使用して、ユーザーからの最新のツイートを表示しています。これはワードプレスにあります。これはほとんどの場合機能しますが、時々、次のエラーが発生します。
file_get_contents( http://api.twitter.com/1/statuses/user_timeline/[username].json ) [function.file-get-contents]: ストリームを開くことができませんでした: HTTP 要求が失敗しました! HTTP/1.1 400 Bad Request in [...]/twitter.php 行 47
Twitter API の制限を超えていないことは間違いありません。キャッシュ コードに欠陥があるとしても、ローカルでホストされているため、他の誰もこれを見ることができず、1 時間に 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 } ?>
これについて何か助けていただければ幸いです。私は完全に困惑しています。