Skip to: Navigation | Content | Sidebar | Footer


Latest Entries

Not a Test

January 3

It's a new year, so it's time for a slight change of direction. You may have noticed your feed reader of choice just barfed up a few dozen posts from these here parts. I'm hoping that little bit of necessary unpleasantness will be one time only.

I've come to realize that my content-creating has become a lot more distributed, which means the long-form post format of this site has been seeing less and less love in recent years. Much has been written about Twitter killing the urge to write longer blog posts, and I won't dispute that as a cause. I liked Andy Budd's take on why his site has been suffering, I can relate to a lot of those reasons.

So for the past month I've been working on a way of piecing together content I produce on other sites and funnel relevant bits into a stream that I could present on this site.

You're now seeing the result. I'm merging my traditional posts with links from Delicious and Google Reader (which is what I was up to when I wrote about the latter's API), photos from Flickr, and Twitter posts (or tweets, if you prefer). The home page, archives, and primary Atom feed all work on this new system.

Totally nuts, right? The volume will be too high, and nobody wants to see every photo I upload or hear every inane thought I come up with while out for dinner. So that's why I'm exercising editorial control and only bringing over the bits and pieces I've hash- or machine-tagged.

Photos on Flickr, for example, can be tagged as either mezzoblue:post=description or mezzoblue:post=photo. Both tags will show the photos here, in slightly different configurations (see the bottom of the August 2008 archive for both).

On Twitter I'm using a hash tag (#mb) which shows up in the original, but I'm stripping from the on-site version. Google Reader pulls in shared items tagged with mezzoblue. And I'm just throwing in everything from Delicious for now, since I got into the habit of using it for the now-deprecated mezzoblue Dailies.

I'm still not sure if I'm going to write up the scripts I built to make this happen, or package it up into some kind of actual open source release. I think the latter way would be more interesting, but there's a lot of work that would have to happen to get to something even slightly worthy of putting out there for public consumption.

Now I do realize that not everyone will want this of course, so the way this site used to work isn't gone. You can follow the clutter free post-only feed, or browse just my original posts on the traditional archive pages. Both are accessible from the main archives page, and will continue to exist. It's just the defaults that have changed, but you can go ahead and ignore all the new stuff if you want.

Expect a few bugs as I stress-test my scripts live over the next few weeks, and let me know if you find anything horribly wrong.

Update: and first major bug has been found: the full Atom feeds weren't ready for prime time at all. For now I've backed out and made the default feed post-only again until I can figure out what's causing old items to duplicate. Sorry about the collateral damage to your feed reader.

Permalink › | 20 comments

today.getYear() returns 109, not 2009. Because that's certainly a year format any reasonable person would expect. Well done, Javascript.

January 3 on Twitter

Using the canvas element brings back memories of hand-coding 3D scenes in POVRay in the late 90's. Which I hated doing then, too.

December 17 on Twitter

Authenticating the Google Reader API

December 11

Last week I finally got around to doing something I've long intended: I moved all my RSS feeds into Google Reader and finally said goodbye to Bloglines. More interesting things have been coming from Google's direction lately, and though there's a public beta of a new version of Bloglines it's been feeling stagnant. The final tipping points for me were the ASP errors the mobile version's byte-trimming service has been issuing up for the past few weeks. So I switched, and after a very brief learning curve, I'm glad I did.

Aside from a nice iPhone-optimized version, one of the new toys I picked up in the switch is an unofficial Google Reader API. It's been in an unofficial state for a whole three years now, with no sign of an actual release, so documentation is sparse at best. This wiki seems to be the definitive source, and for non-programmers like myself, it's mind-bendingly vague.

One of the speculative reasons for the lack of an official release is the authentication currently necessary to log in and start using the API, and that proved to be exactly what I've spent the past few days banging my head against. Unless my Google-fu has weakened, there doesn't appear to be much publicly-available code for using the API, and virtually nothing in PHP. So I figured I'd share what I came up with.

This is a script for logging in with your own account and pulling out your latest unread items in the form of an Atom feed. Drop the script on your server, change the login id and password, and it should work as intended. I haven't explored much yet, and probably will never do anything beyond read-only, so you're on your own past this point. But hopefully it'll save someone a few hours anyway.

// ----------------------------------------
// Google Reader Authentication in PHP
// a basic script to get you in the door of 
// Google's unofficial Reader API
// by Dave Shea, mezzoblue.com
// ----------------------------------------

// cobbled together from notes on:
// http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI

// these are the urls we'll need to access various services
$urlAuth = "https://www.google.com/accounts/ClientLogin";
$urlAtom = "http://www.google.com/reader/atom";

// our array of login data
$login = array(
  "service" => "reader",
  "continue" => "http://www.google.com/",

  // Google id-only of the account holder
  // ie. for example@gmail.com, just use example
  "Email" => "google-id", 

  // the account's password in plaintext
  "Passwd" => "password",

  // an identifying name for your script, can be anything
  "source" => "my reader script",
);


// first step is to authenticae
// let's build a POST request using the login data array
$postRequest = "";
foreach($login as $field => $value) {
  $postRequest .= $field . "=" . $value . "&";
}

// start buffering what we get back
ob_start();
$ch = curl_init($urlAuth);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec ($ch);
curl_close ($ch);
// throw the buffer into a variable
$loginResult = ob_get_contents(); 
ob_end_clean();

// we just received three lines of ugliness to contend with.
// each line is a huge string preceded with an ID
// the IDs are: SID, LSID, and Auth; we only want SID
// let's use some string parsing to weed it out
if ($i = strstr($loginResult, "LSID")) {
  $SID = substr($loginResult, 0, 
    (strlen($loginResult) - strlen($i)));
  $SID = rtrim(substr($SID, 4, (strlen($SID) - 4)));
}
// so we've found the SID
// now we can build the cookie that gets us in the door
$cookie = "SID=" . $SID . 
  "; domain=.google.com; path=/; expires=1600000000";


// this builds the action we'd like the API to perform
// in this case, it's getting our list of unread items
$action = $urlAtom . 
  "/user/-/state/com.google/reading-list";
  // note that the hyphen above is a shortcut
  // for "the currently logged-in user"


// start buffering what we get back
ob_start(); 
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $action);
curl_setopt ($ch, CURLOPT_HTTPGET, true);
curl_setopt ($ch, CURLOPT_COOKIE, $cookie);
curl_exec ($ch);
curl_close ($ch);
// throw the buffer into a variable
$xml = ob_get_contents();
ob_end_clean();

// and finally, let's take a look.
echo $xml;

Permalink › | 6 comments

you mean strtotime("1 month ago") actually *works*? Instant favourite PHP function.

December 11 on Twitter

You mean I don't have to feel ashamed to use MyFonts anymore? http://new.myfonts.com/ is a lovely—albeit way overdue—redesign.

December 9 on Twitter

delving into XML, REST, PHP's curl, and Tylenol.

December 7 on Twitter

Browse Archives › | Full Archive Feed (buggy at the moment) | Post-Only Feed