Created
May 22, 2012 00:11
-
-
Save findzen/2765591 to your computer and use it in GitHub Desktop.
Parse Twitter RSS feed and cache using SimplePie
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 | |
require_once 'lib/simplepie.inc'; | |
require_once 'lib/json_format.php'; | |
$response = array( | |
'tweets' => parse_feed( 'http://search.twitter.com/search.atom?q=from%3acnnbrk+OR+from%3anpratc' ) | |
); | |
function parse_feed( $url ) | |
{ | |
$data = array(); | |
$feed = new SimplePie( $url ); | |
foreach ( $feed->get_items() as $feed_item ) | |
{ | |
$item[ 'author' ] = array( | |
'name' => $feed_item->get_author()->get_name(), | |
'link' => $feed_item->get_author()->get_link(), | |
'image' => $feed_item->get_link( 0, 'image' ) | |
); | |
$item[ 'title' ] = $feed_item->get_title(); | |
$item[ 'timestamp' ] = $feed_item->get_date(); | |
$data[] = $item; | |
} | |
return $data; | |
} | |
header( 'Content-type: text/javascript; charset=UTF-8' ); | |
echo json_format( json_encode( $response ) ); | |
/* EOF */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment