Skip to content

Instantly share code, notes, and snippets.

@wktk
Created August 24, 2012 11:00
Show Gist options
  • Save wktk/3449159 to your computer and use it in GitHub Desktop.
Save wktk/3449159 to your computer and use it in GitHub Desktop.
ツイートを可能な限り遡る
<?php
require './tmhOAuth.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => "",
'consumer_secret' => '',
'user_token' => '',
'user_secret' => '',
'curl_ssl_verifypeer' => false,
));
$last_id = 0;
while (1) {
// '1/favorites' 等も使用可
$tmhOAuth->request('GET', $tmhOAuth->url('1/statuses/user_timeline'), array(
'count' => '200',
'screen_name' => '', // ユーザー名の指定 (未指定時は認証ユーザ)
'include_entities' => 'true',
) + ($last_id ? array(
'max_id' => $last_id
): array()));
$statuses = json_decode($tmhOAuth->response['response']);
if ($last_id) array_shift($statuses);
if (!$statuses) break;
foreach ($statuses as $status) {
echo '"'. $status->id_str. '","'. date('ymd', strtotime($status->created_at)). '","'. str_replace('"', '""', $status->text). '"'. "\n";
}
$last_id = $statuses[count($statuses) - 1]->id_str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment