0
트위터 API로 작업하고 있으며 havent는 예를 들어 지난 1 시간 동안의 트윗을 얻는 방법을 찾았습니까?Twitter API - 지난 24 시간 또는 지난 시간의 트윗을
지난 24 시간 또는 지난 1 시간 동안의 짹짹 올리는 방법을 알아낼 수 없습니다. 누군가 나를 도울 수 있습니까?
내 스크립트는 다음과 같습니다. 이 스크립트는이 루프
foreach ($tweets as $tweet) {
++$tweets_count;
$max_id = $tweet['id'];
}
확인 날짜/트윗 ($tweet['created_at']
)의 시간에
<?php
ini_set('display_errors', 1);
require_once('TwitterAPIClass/TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "XXXXX",
'oauth_access_token_secret' => "YYYYY",
'consumer_key' => "XXXX",
'consumer_secret' => "YYYY"
);
$query = '%24synx';
$max_id = 0;
$tweets_count = 0;
while (true) {
// First API call
if ($max_id == 0) {
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = "?q=".$query."&count=100";
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$twitter_data = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true);
// Repeated API call
} else {
// Collect older tweets
--$max_id;
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = "?q=".$query."&count=100&max_id=".$max_id."";
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$twitter_data = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true);
}
$tweets = $twitter_data['statuses'];
print_r($tweets);
// Exit loop when no more tweets are returned
if (sizeof($tweets)==0) {
break;
}
// Count tweets
foreach($tweets as $tweet) {
++$tweets_count;
$max_id = $tweet['id'];
}
//Sleep 3 seconds after every API call, to not exceed API rate limit
sleep(3);
}
echo $tweets_count;
?>
감사합니다. 어떻게 제대로 할 수 있을까요? 트위터의 "created_at"날짜 형식이 꽤 이상하게 보입니다./ –
UTC 시간 (그리니치 표준시)입니다. 따라서 현지 시간으로 변환하거나 현지 시간을 UTC로 변환하십시오. 이상하게 보입니까? – Jonas
흠 무엇이 내 시간으로 변환하는 가장 좋은 방법은 무엇입니까? 고마워. –