A great new use of the Google API and SOAP

5

OK, I’m convinced. I’ve been toying with Movable Type‘s new Google APIs, and I’ve created something new and really cool.
With a 3-line hack to Movable Type’s source code (gosh, I love having the source code to my software) I added a new function to its Google search capability – I can now do dynamic google searches on each and every one of the titles of my blog posts.
What’s that mean? Well, look down at the bottom of this blog entry. You’ll see a line that starts, “Related Stories:” followed by 10 links. These links are created by a google search on the words in the title of this blog entry.
The reason why I can do this is because Google has created a standardised way to automate queries to its search engine using a protocol called SOAP and the folks at Movable Type have created an interface that takes advantage of SOAP calls. All I needed to do was to add 3 lines of code to the Movable Type codebase to enable the capability seen in the “Related Stories” links below.
In addition, those links get updated each time I post a story – In other words, as Google indexes my pages and others like them, new stories show up whenever I update the index page with a new entry. Additionally, I could run a regular task to automatically refresh my Google related stories links for all of my entries each night as well.
If you’re interested in the patch to the Movable Type codebase, I’ve included it below.


You can get the patch file at http://www.sifry.com/mt-googleapi.patch It is also included below:
+++ Context.pm Wed Jun 19 01:46:44 2002
@@ -1225,10 +1225,13 @@
sub _hdlr_google_search {
my($ctx, $args) = @_;
my $query;
+ my $title;
my $blog = $ctx->stash(‘blog’);
if ($query = $args->{query}) {
} elsif (my $url = $args->{related}) {
$query = ‘related:’ . $url eq ’1′ ? $blog->site_url : $url;
+ } elsif ($title = $args->{title}) {
+ $query = _hdlr_entry_title($ctx);
} else {
return $ctx->error(‘You used without a query.’);
}
In other words, I added 3 lines to the code. The first defines a new $title variable, and the other two test to see if the “title” property is set in the MTGoogleSearch tag, and if so, it sets the $query variable to the entry title stored in the $ctx variable.
To use the new MTGoogleSearch functionality, simply use the title=”1″ property in the MTGoogleSearch tag.
I’ve put up my Movable Type index template file as well so you can see it work in context.

Share

Related posts:

  1. More Google API hacks for Movable Type
  2. Related Stories patch accepted for Movable Type 2.2, Dave Winer’s comments
  3. Google web results significantly different from API
  4. Welcome to the Blogosphere, Google!
  5. Hey, that’s my telephone number on Google!
Posted in: Uncategorized

This article has 5 comments

  1. Glen Campbell 06/19/2002, 8:35 am:

    Way cool – good work.

  2. Jonathan Peterson 06/19/2002, 9:59 am:

    This is sweet. Of course it requires writting meaningful as opposed to clever titles, but still very, very cool. I could also see modifying the search to return only results in your own domain, creating automatic self-referential interconnections. The only downside is the same as that of the googlebar, this will programmatically increase the link weighting of the top items returned for searches. But that is a problem that Google will have to address anyway.

  3. tyler weir 06/19/2002, 11:05 am:

    this is bad ass.
    as jonathan said above it’s time to start thinking of titles that are better than *did you ever notice?* and *a quick note.*
    bravo.

  4. rob 06/19/2002, 11:06 am:

    for the idiots like me out there… This code is places as-is into Context.pm? Where do I set the google key? It creates many errors upon the rebuild site.

  5. rob 06/19/2002, 11:25 am:

    i put the above in a patchfile and ran patch on it, replacing google_api_key with my key… patch reports
    Hmm… Looks like a unified diff to me…
    The text leading up to this was:

Across the Web

  • Facebook
  • Twitter
  • Flickr
  • Youtube

Twitter

Javascript needs to be installed to view the twitterfeed. Get Javacript

Follow Me on Twitter