Created
July 23, 2015 13:05
-
-
Save kaz/0b1238c3ac1ed6452504 to your computer and use it in GitHub Desktop.
This file contains 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 | |
if(!array_key_exists("q", $_GET)) exit("no query"); | |
$ch = curl_init(); | |
curl_setopt_array($ch, [ | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_SSL_VERIFYPEER => false, | |
CURLOPT_URL => "https://twitter.com/i/search/timeline?" . http_build_query([ | |
"q" => $q = $_GET["q"], | |
"src" => "typd", | |
"vertical" => "default", | |
"include_available_feature" => 1, | |
"include_entities" => 1, | |
"last_note_ts" => time(), | |
"max_position" => array_key_exists("c", $_GET) ? $_GET["c"] : "" | |
]) | |
]); | |
$resp = json_decode(curl_exec($ch), true); | |
curl_close($ch); | |
preg_match_all('@data-user-id="(\d+)">.+?fullname.+?>(.+?)</strong>.+?href="/(.+?)/status/(\d+)".+?data-time="(\d+)".+?(<p.+?)</p>@s', $resp["items_html"], $tweets, PREG_SET_ORDER); | |
foreach($tweets as &$entry){ | |
$entry = [ | |
"UserID" => (int)$entry[1], | |
"FullName" => $entry[2], | |
"ScreenName" => $entry[3], | |
"StatusID" => (int)$entry[4], | |
"Time" => $entry[5], | |
"Status" => preg_replace("@<.+?>@", "", preg_replace('@<a href="(http.+?)".+?/a>@', "$1", $entry[6])) | |
]; | |
} | |
$c = $resp["min_position"]; | |
$next = "http://{$_SERVER["SERVER_NAME"]}{$_SERVER["SCRIPT_NAME"]}?" . http_build_query(compact("q", "c")); | |
header("Content-Type: application/json; charset=utf-8"); | |
echo(json_encode(compact("next", "tweets"))); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment