$cache_file = "cache/$username-twitter.cache";
$last = filemtime($cache_file);
$now = time();
$interval = $interval * 60; // ten minutes
// Check the cache file age
if (!$last || (($now - $last) > $interval)) {
// cache file doesn't exist, or is old, so refresh it
// Get the data from Twitter JSON API
//$json = @file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=" . $username . "&count=" . $count, "rb");
$twitterHandle = fopen("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$username&count=$count", "rb");
$json = stream_get_contents($twitterHandle);
fclose($twitterHandle);
if($json) {
// Decode JSON into array
$data = json_decode($json, true);
$data = serialize($data);
// Store the data in a cache
$cacheHandle = fopen($cache_file, 'w');
fwrite($cacheHandle, $data);
fclose($cacheHandle);
}
}
// read from the cache file with either new data or the old cache
$tweets = @unserialize(file_get_contents($cache_file));
return $tweets;
물론 $ 사용자 이름과 fopen을 요청 내부의 다른 변수 올바른지과
경고 : I 오류 얻을 수 있기 때문에 올바른 URL을 생성하면 fopen을 (http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Schodemeiss & 수 = 5) function.fopen] : 스트림을 열지 못했습니다 : HTTP 요청이 실패했습니다! HTTP/1.1 400 잘못된 요청 /home/ellexus1/public_html/settings.php 온라인 187
내 페이지를 열려고 시도 할 때마다 ^^ 오류가 반환됩니다.
왜 이런 생각일까요? OAuth를 사용하여 내 트윗을 가져와야합니까? 내 웹 사이트를 게시물을 올릴 수있는 곳에 등록해야합니까?
왜 이런 일이 발생하는지 잘 모르겠습니다. 제 호스트는 JustHost.com입니다. 그러나 그것이 어떤 차이가 있는지 확실하지 않습니다. 모든 아이디어는 환영합니다!
감사합니다.
앤드류
ps. 이 코드는 username, interval 및 count가 올바르게 전달되는 함수 내부에 있으므로 오류 코드에서 올바른 형식의 주소가 생성됩니다.
이상한에 제시되어있다
https://dev.twitter.com/overview/api/response-codes
오류 도움이 될 수
fopen
와바꾸기, 그것은 나'컬 작동 - D - "http://api.twitter.com/1/statuses/user_timeline.json?screen_n ame = Schodemeiss & count = 5 "' –