Using SimplePie to access shared items in Google Reader
This is a quick overview on how to access your shared items in Google Reader using PHP. Since Google Reader publishes your shared items to a RSS feed, we can access your feed using a PHP library called SimplePie.
You can trivially connect to your shared items feed with the following lines of code:
$feed = new SimplePie(); $feed->enable_cache(false); $feed->set_feed_url($feed_url); $feed->init(); $feed->handle_content_type(); $items = $feed->get_items();
We can then loop through the items and easily grab the Title, Author, and Link of the shared item.
foreach($items as $item) { $data = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, "source" ); $link = $data[0]['child']['http://www.w3.org/2005/Atom']['link'][0] ['attribs']['']['href']; $created = $data[0]['child']['http://www.w3.org/2005/Atom']['title'] [0]['data']; $title = $item->get_title(); $content = "<a href=\"".$item->get_permalink()."\">".$item->get_title() ."</a> (<a href=\"$link\">$created</a>)"; }
Google Reader, also, allows you to post a note to any item that you share in Google Reader. This is, also, conveniently put into the shared-item RSS Feed which we can grab using SimplePie.
$note_data = $item->get_item_tags( "http://www.google.com/schemas/reader/atom/", "annotation" ); $note = $note_data[0]["child"]["http://www.w3.org/2005/Atom"] ["content"][0]["data"];