Tag Archives: blogger

gpowered.net is now timbroder.com

Hi all,

some of you may have noticed this site is no longer on the gpowered.net domain.  I’ve been wanting to move onto wordpress for a while now and also do some additional writing beyond code stuffs which would be outside of the scope of gpowered.  I also unfortunately (or fortunately because I love my job) don’t have as much time as I used to to research and post how to’s.  Heavy django and magento going on lately, I’ll try to post about those.

There are two RSS links at the top, RSS has everything on this site including gpowered.  the gpowered RSS will continue to contain only tech articles.

Let me know of any issues on the new site

Google I/O session videos posted with slides

As I said earlier, Quite a few presentations from Google I/O have been posted for your viewing pleasure. I’ll be glued to these this weekend while I’m on call.

Topics include
Ajax
KML
Sketchup
Android
OpenSocial
Appengine
Data APIs
Theory Talks
Youtube
Gears
Mashups
Maps
and more!

Blogger adds bloggroll

Blogger in draft added 2 new features today: a blogroll page element, and post scheduling. Post scheduling is pretty useful, you can write up your post, set the time (in the future) that you want it to post, and Blogger will do it automatically.

The second feature, a blogroll, I would like a lot more if it was done better. The main thing I like about it is that it integrates with Google Reader so if I’m linking to my friend’s blogs, I just scroll to my ‘Friends’ Tag and add them. The thing I don’t like however is that it does not support XFN or FOAF therefore not getting picked up by the SocialGraph API. For example, if I linked to my girlfriend’s blog, the blogroll just lists this as

Maybe-Not

A better link, for example from a wordpress blogroll would look something like

Maybe-Not< 

...and get picked up but the SocialGraph as having a relationship to me. Blogger is great and I love using it, but the features of wordpress are blowing it out of the water.

October Speedlinking

I haven’t been able to post as often or as in depth as I’d like to have this past month. I chalk it up mostly to work, we all love 12 hour days right? But now that sign-off has passed and our last release of 2007 is calmly approaching (its on Friday), things have settled down a bit. Below are some great links from October, most of which I wanted to mention at some point and haven’t gotten a chance to until now. Enjoy.

Using Blogger and Feedburner Sitemaps in Webmaster Tools

Blogger, good. FeedBurner, good. Google Webmaster tools, good. The 3 working together? A little more difficult. A few months ago blogger added support to have FeedBurner + blogger integration. No more editing template code, just change a setting in blogger, and viola, FeedBurner will track all your subscribers. However, this method did not go over so well with Google Webmaster Tools. Previously you could just add your blog’s feed as a sitemap for you blog and the Google Bot would have no problem. If you turned on FeedBurner however, sitemap errors popped up all over because the FeedBurner links were on a different domain from the blog, etc..

Here is a way to make it work (assuming you already have a blog set up):

  1. Make an account on FeedBurner and add your blog to it

  2. Then, in blogger go to settings > Site Feed > Post Feed Redirect URL and add your FeedBurner feed

  3. Finally, if you want to track your blog in Google Webmaster Tools you will have to add the sitemap a little differently then normal. Add a General Web sitemap as the “rss.xml?orderby=updated” feed off of your blog. FeedBurner does not pick up this feed in the redirects, so the Google Bot will not have trouble with it.

  4. After this your site will be tracked by FeedBurner as well as Google Webmaster tools and the Google Bot will be able to use the sitemap properly

Blogger resumes service

Blogger was down this morning from a little after 9:30 until a few minutes ago, but now, all is well…

HOWTO: Getting a list of post titles from blogger (Python)

This will be a quick one on how to pull the titles from your blog. I’m using it to Lists the posts I have available on gPowered.net. Firstly we’ll set up our imports and call to the blogger service.

from elementtree import ElementTree
from gdata import service
import gdata
import atom
import getopt
import sys

blog_id = 413573351281770670
blogger_service = service.GDataService('timothy.broder@gmail.com', '*****')
blogger_service.source = 'Blogger_Python_Sample-1.0'
blogger_service.service = 'blogger'
blogger_service.server = 'www.blogger.com'
blogger_service.ProgrammaticLogin()

For this query we’re going to use the summary feed because all we really need for this is the titles, not the full posts:

query = service.Query()
query.feed = '/feeds/' + str(blog_id) + '/posts/summary'
feed = blogger_service.Get(query.ToUri())

Then I just do a little counting so I can use the links on my site. All the information we need is in feed.entry

curr_id = int(feed.total_results.text)
for entry in feed.entry:
 entry.my_id = curr_id
 curr_id -= 1

HOWTO: Displaying Blogger feeds with PHP

This HOWTO is going to follow the basic structure of the Python one.

To start out you’ll have to grab the Zend Google data Client Library and then set the include_path so you can use it

ini_set("include_path", ".:../:./include:../include:/home/gpowered/webapps/php/includes/ZendGdata-1.0.1/library");

We then import the parts the we’ll need:

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

One of the first things we’re going to have to do is authenticate with google services.
There are two ways to do this: AuthSub proxy authentication which has a user login using their own credentials, and
ClientLogin username/password authentication where you send a username and password. We will be using ClientLogin. I built a small class called gPoweredBlogger to hold the different parts I will need for this example.

class gPoweredBlogger{
 private $user;// = 'timothy.broder';
 private $pass;// = '**************';
 private $service;// = 'blogger';

 private $blog_id;// = '413573351281770670';
 private $uri;// = "http://www.blogger.com/feeds/" . $blog_id . "/posts/default";
 private $show_num;// = 5;

 private $client;// = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
 private $gdClient;// = new Zend_Gdata($client);
 private $query;// = new Zend_Gdata_Query($uri);

 private $total_posts;

 public $output;

Then we start setting up our call to the service.

 public function __construct($user, $pass, $blog_id){
  $this->user = $user;
  $this->pass = $pass;
  $this->service = 'blogger';

  $this->blog_id = $blog_id;
  $this->uri = "http://www.blogger.com/feeds/" . $this->blog_id . "/posts/default";
  $this->show_num = 5;

  $this->client = Zend_Gdata_ClientLogin::getHttpClient($this->user, $this->pass, $this->service);
  $this->gdClient = new Zend_Gdata($this->client);
  $this->query = new Zend_Gdata_Query($this->uri);
  $this->total_posts = $this->get_total($this->query);
 }

For more info see the blogger developer’s guide with php or the Google Account Authentication documentation
After we have authenticated with Google we need to start building up our query to GData. The first thing you’ll need is your blog’s id.
You can use the function in the dev guide to help you with this if you don’t already know it.

Like the Python version, the below function returns the total number of posts that are in the feed. We can get a small response by sending 0 for the max results. Below is the function and the small response we get from it.

 private function get_total($query){
  //query for no posts
  $this->query->setParam('max-results', '0');
  $this->query->setParam('start-index', '1');

  //get back entryless feed
  $feed = $this->gdClient->getFeed($this->query);
  return $feed->totalResults->text;
 }

 5
 0
 1
 Blogger
 Tim
 tag:blogger.com,1999:blog-413573351281770670
 
 
 
 
 gPowered
 2007-07-18T10:55:06.728-05:00

So we get the total number of posts and then we can start pulling data. Lets make a generic function, PostFrom, that can be used to show multiple posts, or just single ones, depending on what you pass to it. The start number that is passed to
PostFrom has been set to the first post in the blog is considered to have an id of 1 and the latest post is the same as total_posts. This is useful so if viewers want to bookmark the page they are looking at, the post that is being displayed will not change.
The following are the different functions that will make use of it.

 //show latest posts
 public function Posts(){
  return $this->ListPosts($this->total_posts);
 }

 //show posts starting from a certain point
 public function ListPosts($start){
  $start = $this->total_posts - $start + 1;
  return $this->PostFrom($start, $this->show_num);
 }

 //show a single post
 public function Post($start){
  $start = $this->total_posts - $start + 1;
  return PostFrom($start, 1);
 }

 //show count number of posts starting from a certain point
 private function PostFrom($start, $count){
  //query for count number of posts starting at the given post
  $this->query->setParam('max-results', $count);
  $this->query->setParam('start-index', $start);
  $feed = $this->gdClient->getFeed($this->query);

Now we have all the data we need in the feed variable. Its been turned into an object so we don’t have to worry about XML parsing here. Every node has become an objects and lists. Objects for single nodes(title), and lists for where there are multiple nodes of the same name (entry, link)

  //for links
  $curr_id = $this->total_posts - $start + 1;

  //normalize data for output
  foreach($feed->entries as $entry){
   //id for links
   $entry->my_id = $curr_id;
   $curr_id -= 1;

  }

Of course we’re going to need next and previous buttons as well. The way we’ve set up the math with total_posts and the start number, we only have to increment or decrement these by count (the number of posts to display on a page). I also set part of the link, as well as the page title, that I will use below in the HTML.

  $prev = $this->total_posts - ($start - $count) + 1;
  if($prev > $total_posts){
   $prev = null;
  }

  $next = $this->total_posts - ($start + $count) + 1;
  if($next < 1){
   $next = null;
  }

  //showing single post
  if(count == 1){
   $link = 'post';
   $title = $feed->entries[0]->title->text;
  //listing posts
  }
  else{
   $link = 'posts';
   $title = 'home';
  }

The final part is to make a quick object that we can use in the HTML to output everything

  $this->output = new Output($feed->entries, $title, $prev, $next, $link);
 }
} 

class Output{
 public $entries;
 public $title;
 public $prev;
 public $next;
 public $link;
 public function __construct($entries, $title, $prev, $next, $link){
  $this->entries=$entries;
  $this->title=$title;
  $this->prev=$prev;
  $this->next=$next;
  $this->link=$link;
 }
}

To the HTML!

The first part consists of displaying the post itself, along with its relevant information. So lets built up our objects

$blog = new gPoweredBlogger('timothy.broder', '*************', '413573351281770670');
$blog->Posts();

$output = $blog->output;

Below all the php we can run through out output object and display the posts

<? foreach($output->entries as $entry){ ?>
     <h2><a href="/post/<? echo $entry->my_id ?>"><? echo $entry->title->text ?></h2></a>
     <? echo $entry->content->text;
     $datetime = strtotime(substr($entry->published, 0, 10) . ' ' . substr($entry->published, 11, 8 ));
     ?>
     <p>Posted by <? echo $entry->author[0]->name->text ?> on <? echo date("m/d/Y",$datetime) ?> at <? echo date("g:i a",$datetime) ?></p>

      <div id="divider"></div>
      <?}?>

That’s all for now. A working example is here

Performance Optimization WordPress Plugins by W3 EDGE