현재 Twitter API를 통해 사용자 시간대를 탐색하는 웹 응용 프로그램을 작성하고 있습니다. 데이터를 가져 오거나 조작하는 데 문제가 없습니다. 내가 가진 문제는 속도 다. Twitter API는 검색 할 수있는 트윗 수를 페이지 당 200 개로 제한합니다. 페이지 매김은 이전 페이지에서 마지막으로 읽은 짹짹 인 (max_id)에 매개 변수를 전달하여 ID를 통해 수행됩니다. 아무도 내가이 짹짹을 얻을 수있는 속도를 높이려는 생각을 할 수 있습니까? 나는 abraham oauth lib를 사용하고 있습니다. 내 코드는 다음과 같습니다 :사용자 시간대 루핑 - Twitter API
$twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth['oauth_token'], $oauth['oauth_token_secret']);
$tweets = $twitteroauth->get('statuses/user_timeline', array ('screen_name' => 'user_name', 'count' => 200));
// get first batch of tweets from api
foreach($tweets as $t)
{
$tweets_to_process[] = $t;
}
// get last id of tweet and set prev_id to 0
$last_id = $tweets_to_process[count($tweets_to_process)-1]->id_str;
$prev_id = 0;
$loop_num = 0;
// loop through pages whilst last page returned of api result does not equal last of last result
while($last_id != $prev_id && $loop_num < 4)
{
// get tweets
$tweets = $twitteroauth->get('statuses/user_timeline', array ('screen_name' => 'user_name', 'count' => 200, 'max_id' => $last_id));
// loop through tweets and add to array
foreach($tweets as $t)
{
$tweets_to_process[] = $t;
}
// set prev and last id
$prev_id = $last_id;
$last_id = $tweets_to_process[count($tweets_to_process)-1]->id_str;
$loop_num ++;
}
는 최대 3,200 트윗을 통해 반복이보기의 UX 지점에서 너무 오래 걸리는 때문에이 while 루프에서 휴식 카운터를 넣어 한 순간에 볼 수 있듯이.
안녕하세요 - 앱이 실시간입니다. 사용자가 '로그인'한 다음 데이터가이 사용자의 타임 라인에 대해 끌어 당겨 지므로 불행히도 미리 정의 된 간격으로 데이터를 가져 오지 못합니다. 누구를 사용하고 있는지 알지 못하기 때문에 불가능합니다. –