Show Shared Google Reader Items on Your Site
Google recently launched some updates to Google Reader. This includes the ability to search for users who are sharing items publicly from within Reader. You can also search for keywords to find people who are talking about topics of interest to you.
Another addition, is a small icon that you can click to say you liked a particular post. Your name is then shown publicly so that others can see what type of content you are interested in. Google have taken a more social approach to Reader with a few simple additions to what (in my opinion) is probably the best RSS reader around at the moment.
If like me you regularly Share items that you read on Google Reader, you may want to syndicate recent Shared Items on your website. Google provide a simple widget that can be adapted in Google Reader’s settings page and then cut-and-pasted into your website. However, this widget has limitation in terms of integration into your sites overall design.
Another approach is to parse the Atom feed from your Shared Items page.
Use Magpie RSS to Parse Your Feed
1. First you will need to download the latest version of Magpie RSS from here.
2. Unzip Magpie RSS.
3. Download the following rss_parse.inc.txt file (thanks to John Mueller) and save the file as rss_parse.inc (I.e. remove the .txt extension). IMPORTANT: this file replaces the standard rss_parse.inc file that comes with Magpie RSS, so save this file over the rss_parse.inc file in the Magpie RSS folder that you just unzipped.
4. Create a folder for Magpie RSS on your server and upload all the files to this folder. (Remember to upload the adapted rss_parse.inc file from step 4 instead of the rss_parse.inc file that came with Magpie RSS).
5. Within the main Magpie RSS folder on your server, create a subfolder called ‘cache’ and CHMOD the folder to 755 (drwxr-xr-x).
6. Now add the feed to your webpage. The page needs to be saved with the .php file extension. Add the following code to the top of your page (before your HTML content) and adapt the path to cache folder and path to rss_fetch.inc file.
<?php
// You must include this PHP block in your template once
// The required settings for Magpie
define('MAGPIE_CACHE_DIR', '/home/abcxyz/public_html/magpierss/cache');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
// include the main file
require_once('/home/abcxyz/public_html/magpierss/rss_fetch.inc');
?>
7. Now locate the URL for your Google Reader Shared Items page (E.g. this is mine) and copy your unique number from the URL.
8. Paste your unique number into the code below instead of the asterisks, then copy-and-paste the following code into your page where you want your Shared Items list to be displayed.
<h4>Google Reader Shared Items</h4>
<ul>
<?php
// Settings (modify as required):
// your Google Reader shared items feed URL
$sharedfeedurl = 'http://www.google.com/reader/public/atom/user/**********************/state/com.google/broadcast';
// the (X)HTML page for your Google Reader shared items
$sharedpageurl = 'http://www.google.com/reader/shared/**********************';
// maximum number of items displayed
$maxitems = 10;
// just in case, some filters
$htmlfind = array('"', "<", ">"); // search for these
$htmlreplace = array(""", "<", ">"); // replace with these
// This part displays the shared items feed
$rss = fetch_rss($sharedfeedurl);
$countitems = 1;
foreach ($rss->items as $item ) {
// get title
$posttitle = str_replace($htmlfind, $htmlreplace, $item[title]);
$showtitle = $posttitle;
// trim the title, if it's too long
if ( strlen($showtitle) > 50) $showtitle = substr($showtitle, 0, 49) . ' ...';
$posturl = $item[link];
$siteurl = $item["link_"];
$sitename = $item["title_"];
// adjust the output format, if desired (otherwise style via CSS)
echo '<li><a title="' . $posttitle . '" href="' . $posturl . '" rel="external">' . $showtitle . '</a>';
echo '<span>';
echo '<br /> from <a title="' . $sitename . '" href="' . $siteurl . '" rel="external">' . $sitename . '</a>';
echo "</li>
";
$countitems += 1;
if ($countitems > $maxitems) break;
}
?>
<li><a href="<?php echo($sharedpageurl);?>" rel="external">Read more of my shared items...</a></li>
</ul>
9. Upload your page to your server, and all-being-well, you should see the last 10 items from your Shared Items in a bullet point list.
Additional Options
1. You can choose how many posts are shown by adjusting the following line of code in the page content:
// maximum number of items displayed $maxitems = 10;
2. Long titles are automatically truncated but you can change this setting by adjusting the following line of code in the page content:
// trim the title, if it's too long if ( strlen($showtitle) > 50) $showtitle = substr($showtitle, 0, 49) . ' ...';
I have been looking for such a thing to customize the display of my Google Shared items. This exactly solved my problem.
Thanks for the tutorial.
I’m glad it was useful Ashwin. Thanks
Thank you very much!
I will be giving this one a go young man.
First Off, let me commend your uncloudedness on this subject. I am not an expert on this subject, but after studying your article, my understanding has improved well. Please tolerate me to take hold of your rss feed to stay in touch with any forthcoming updates. Solid job and will pass it on to acquaintances and my web site readers.