Created
May 30, 2021 18:14
-
-
Save ichii731/a8e66e3665c4c5b09ad36cf0b5ed0a16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
set_time_limit(0); | |
require_once('lib/Phirehose.php'); | |
require_once('lib/OauthPhirehose.php'); | |
class FilterTrackConsumer extends OauthPhirehose | |
{ | |
public function enqueueStatus($status) | |
{ | |
// ここの関数内で受信時の処理を書いていきます | |
$data = json_decode($status, true); | |
if (is_array($data) && isset($data['user']['screen_name'])) { | |
$text = preg_replace('/[\n\r\t]/', '', $data['text']); | |
$timeline = $data["id"] . "," . $data['user']['screen_name'] . ',' . $data['created_at'] . ',' . urldecode($text) . ",\n"; | |
echo $data["id"]; | |
$timeline = mb_convert_encoding($timeline, 'SJIS-win', 'ASCII, JIS, UTF-8, SJIS'); | |
file_put_contents("sample.csv", $timeline, FILE_APPEND); | |
} | |
} | |
} | |
// APIの情報を定義 | |
define("TWITTER_CONSUMER_KEY", "*******************************"); | |
define("TWITTER_CONSUMER_SECRET", "***************************************************"); | |
define("OAUTH_TOKEN", "************************************************"); | |
define("OAUTH_SECRET", "*********************************************"); | |
// 実行 | |
$sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); | |
$sc->setTrack(array('keyword1', 'keyword2')); | |
// 日本語指定 | |
$sc->setLang('ja'); | |
$sc->consume(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment