Publish Google Reader Shared Items

A lot of people are using the shared items feature in Google Reader to publish what they are reading on a blog. It’s like having a live blogroll widget on your website. And gives your readers a good impression of what you are actually interested in.

I never bothered adding this to my blog. But i do like to share. So last night i was trying to figure out how to integrate this with my current blog. I was hoping for an easy implementation. But the information is scarce. So i had to do some digging. I did find a couple of Wordpress plugins. But most of them were not updated for at least a year. And i am not putting code like that life on my website.

After some Googling i came across a couple of feed URL’s that seem to share their shared items in feed form. Using the Google Reader URL and a user id. So the URL for my shared items would look like the one below. Getting your user id by the way is easy. Go to your Google reader page. Click all All items and the UID will show up in the address bar.

http://www.google.com/reader/shared/16525759780220726764

The problem with this however. Non of my shared posts show up on this page. And i have not figured out a way to populate it just yet. So i came up with an other path to get this data on my server.

In the Google Reader pages it’s possible to add sharing functionality. This is done by going to the Send To tab

From here it’s possible to select a service to share data with. Non of these services are any good for what i am trying to do. But the great thing about this page is. You can provide custom URL’s for sharing data. Just incorporate the specified parameters in the URL and your done.

Once configured and saved a custom URL is visible in the Send To panel

That’s it for this part. Actually sharing items is quite easy now. When back in the Google Reader under each post there is Send to link. If you click this link the newly created custom URL will show up. And you can share the post.

The only thing left to do is write some code to process the incoming data. To get you started. Some of the code i used while testing this is posted below

GoogleReaderShare class
Class GoogleReaderShare
{
  const GOOGLE_REMOTE_IP = '95.97.54.3';
            
  const GOOGLE_REFERER = 'http://www.google.nl/reader/view/';
            
  protected static $_whitelist = array('source', 'title', 'url', 'short');
            
  public static function CheckSource($remoteAddr, $referer) 
  {
    if (($remoteAddr == self::GOOGLE_REMOTE_IP) 
        && ($referer == self::GOOGLE_REFERER)) {
      return true;
    }
    return false;
  }
            
  protected static function _CheckIncomingData($data)
  {
    if (!is_array($data)) {
      return false;
    }
                            
    foreach ($data as $key => $value) {
      if (!in_array($key, self::$_whitelist)) {
        return false;
      }
    }
  }
            
  public static function Process($data) 
  {
    if (!self::_CheckIncomingData($data)) {
      throw new Exception("Unrecognized or no incoming data");
    }
                    
    // process the data
  }
 
  if (GoogleReaderShare::CheckSource($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_REFERER'])) {
    GoogleReaderShare::Process($_GET);
  }
comments powered by Disqus