Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.


A Squeeze of Python to give me a Buzz

I've been learning Python.

I know, I know....

It starts with Google Buzz. I accept web pages and window apps as the only choices to see social media output from places like Identica, Twitter, Facebook, etc. But my preference is to type things on the command line for most of my content-generating needs. If I wanted to send the same thought to most of my microblogging sites, I just pipe it together.

echo My oh-so-crucial thought | | |

So far, two things have been standing in my way. Facebook and Google Buzz. I have yet to find ways to use my beloved Perl to write to either. But I poked around and found some sample code on the Google Buzz API page. Specifically, I found, which does write to Buzz, but it will not easily integrate to my preferred way. Specifically, it takes in your key and secret as command-line flags and accepts your Buzz update via STDIN. If that's how you roll, that's fine, but for me, the message is join ' ' , @ARGV . So, I recoded it, taking more out than I put in, and using some of my very slight knowledge of Python, to make this. I have the key and secret hard-coded, which is kinda acceptable for personal use but still not to be accepted. You should use the that comes with buzz-python-client to set up your OAuth if you use this, because anything that would do that has been brutally ripped from the original code.

Expect Perl code based on this to come around eventually. For now, enjoy buzz-python-client and my addition.

# Copyright 2010 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import traceback
import getopt

# Load Buzz library (if available...)

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import buzz
except ImportError:
print 'Error importing Buzz library!!!'

token = verification_code = buzz_client = ''

# Function to obtain login data

def GetLoginData():
'Obtains login information from either the command line or by querying the user'

global token, verification_code, buzz_client
buzz_client.build_oauth_access_token(key, secret)

# Main program starts here

buzz_client = buzz.Client()
args = sys.argv
del args[0]
message = ' '.join(args)
message = message.strip()
post = buzz.Post(content=message)
print message
print '\nBzzzz! Something broke!!!'
print '-' * 50
print '-' * 50


  1. WWW::Facebook::API allows posting to Facebook, for what it's worth -- you can see my seriously-not-ready-for-primetime solution to your problem at

  2. Grr, that URL should be

  3. Thanks, gene. I saw WWW::Facebook::API but didn't think it was for this sort of stuff. I thought it was more "Make your own quiz or game" than that.

  4. Nope, it's pretty much full access to their (pretty annoying, IMO) API -- have a look at , specifically the 'set()' method.

  5. Yeah, it's grim. I'm having real problems getting to the point where I can authenticate. ICK ICK ICK. But my twitter friends are my geek friends and my facebook friends are my real-life friends, churchgoers and parents and such. I don't want to use a Twitter->Facebook bridge. GRRR.

  6. There's some sample code at that builds a client.

    There's also a little CLI script at that will help you get a session key once you've got your API key and secret -- this was the most confusing part for me.

  7. Gene, it's the most confusing part for me, too. It seems to want me to tell it where to go next, and I'm struggling to keep from telling it where to go.