Created
January 30, 2009 01:11
-
-
Save jdp/54870 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 | |
/** | |
* Chirp 'people' API method | |
* @author Justin Poliey <[email protected]> | |
* @package chirp | |
* @version 1.0 | |
*/ | |
/** | |
* Require base API handler | |
*/ | |
require '../core/apihandler.php'; | |
/** | |
* Require Twitter Search component | |
*/ | |
require '../core/twitter.php'; | |
/** | |
* Require Bitly component | |
*/ | |
require '../core/bitly.php'; | |
/* | |
* Enforce API syntax | |
*/ | |
if (!array_key_exists('hash', $_GET)) | |
{ | |
header('HTTP/1.1 400 Bad Request'); | |
$error = array('error'=>'Missing hash parameter'); | |
echo json_encode($error); | |
exit; | |
} | |
/* | |
* Perform a Twitter search for the #chirp hashtag and a Bitly URL specified | |
* in the GET 'hash' parameter. This automatically paginates, and returns a | |
* JSON object of all the instances of that Chirp'd URL. | |
*/ | |
$search = new TwitterSearch(); | |
$page_results = new stdClass(); | |
$search_results = array(); | |
$q = sprintf('http://bit.ly/%s', $_GET['hash']); | |
do | |
{ | |
$query = (property_exists($page_results, 'next_page')) | |
? $page_results->next_page | |
: sprintf('?q=%s', urlencode($q)); | |
$page_results = json_decode($search->rawSearch($query)); | |
foreach($page_results->results as $page_result) | |
{ | |
array_push($search_results, array( | |
'user' => $page_result->from_user, | |
'time' => $page_result->created_at, | |
'status' => $page_result->text | |
)); | |
} | |
} while(property_exists($page_results, 'next_page')); | |
/* | |
* Set the status code and content-type, and then show the JSON | |
*/ | |
header('HTTP/1.1 200 OK'); | |
header('Content-type: text/plain'); | |
echo json_encode($search_results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment