So you just got into Google Buzz few days ago and would like to embed your buzz stream into a website yourself. Here are a few jQuery lines to help you get started.
Like the article? Be sure to subscribe to our RSS feed and follow us on Twitter to stay up on recent content.
Pure Javascript solutions usually incorporate the JSON format [The Fat-Free Alternative to XML] since it is lightweight, very easy to traverse. However, since Google Buzz was launched last Tuesday they still haven’t offered a JSON format of the Buzz feed yet.
Google Buzz API provides your buzz stream in Atom format. But, under the “same origin policy” you can’t pull data (like Atom) from another domain without using JSONP [a complement to the base JSON data format]. So, that’s when another Google service comes to the rescue: Google AJAX Feed API, a proxy that downloads your Atom/RSS feed and converts it into JSON format.
Now let’s go through the implementation steps:
1. CSS First
Buzzes will be added as unordered list. So, these are few CSS lines to clear margin and padding on the unordered list element and style buzz items to looks like rows.
/* ul list */
ul.gb{
padding:0;
margin:0;
}
ul.gb li{
border-bottom:silver 1px solid;
float:left;
margin:1px 0 1px 0;
padding:2px;
list-style-type:none;
height:48px;
overflow:hidden;
width:100%;
}
/* Buzz date */
ul.gb span.gb-meta {
display:block;
margin:3px 0 0 0;
}
ul.gb span.gb-meta a{
font-size:95%;
color:green;
text-decoration:none;
}
2. Include jQuery
We’ll include jQuery library from Google’s high speed content distribution network.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
3. Call When Ready
Then call the jQuery function when “document ready“, to start executing the function when the DOM is fully loaded. This will ensure that Javascript will find the referenced HTML elements.
$(document).ready(function(){
getGoogleBuzz('mikedotmore', 5, $('#my-buzz'));
});
The function takes 3 parameters: Google username, Number of entries to return, and jQuery Object of the placeholder.
4. The Function’s Process…
- The function code starts by specifying few parameters for the Google Feed API as such: getGoogleBuzz( ‘Buzz feed username‘ , number of entries , $(‘#id of placeholder‘) );
- Call jQuery AJAX function and define a function to be called when the JSON data is returned.
- Show error message if Google Feed API couldn’t retrieve the Buzz stream.
- Append a hidden unordered-list to the placeholder.
- Loop each Buzz entry of the entries array, and…
- Parse publishedDate into a Date object.
- Convert links that start with “http” or “https” into hyperlinks.
- Append List item element with Buzz content.
function getGoogleBuzz(username,n, div){ // params for Google Feed API proxy : Buzz Feed URL, Number of Entries var data = {q:'http://buzz.googleapis.com/feeds/'+username+'/public/posted' ,num:n ,output:'json' ,v:'1.0'}; // call Google Feed API $.ajax({ url:'http://ajax.googleapis.com/ajax/services/feed/load' ,data:data ,dataType:'jsonp' ,success:function(json){ // json from Google Feed API was returned successfully.. // error with Google Buzz feed ? if(json.responseStatus!=200) { div.html('<b style="color:red">'+ json.responseDetails +'</b>'); return; }; // Buzz entries array var entries= json.responseData.feed.entries; var length= entries.length; // no entries! if(length==0) return; // start output by appendding a hidden unordered list var ul = $('<ul class="gb" style="display:none"></ul>').appendTo(div.html('')); // loop buzz entries for(var i=0; i<length; i++){ // parse published-date string var pDate = new Date(entries[i].publishedDate); // using entry snippet version var snippet = entries[i].contentSnippet; // convert links that start with http to hyperlinks using regular expression snippet = snippet.replace(/\b(https?\:\/\/\S+)/gi,' <a href="$1">$1</a>'); // append buzz to UL ul.append('<li>' +'<span class="gb-content">'+ snippet +'</span>' +'<span class="gb-meta">' + '<a href="'+ entries[i].link +'">'+ pDate.toLocaleString() +'</a>' +'</span>' +'</li>'); }; // now show-in the unordered list ul.show('slow'); } }); }
5. Add a Placeholder
This is the div element that will hold your buzzes with id set to “my-buzz”
<div id="my-buzz">loading...</div>
Be alert though! Google Buzz is still brand new, and the rules of the game may be changed later. So, stay tuned…



nice post…i will use it in my blog…
Good Post! Wonder if Google buzz will be really required after Facebook and Twitter
thanks for the tuts, and using jquery – new one
.-= sriganesh´s last blog ..Top commentators gets free Ad slot each month =-.
Not sure if I want to share my Google Buzz’s just yet!
Google Buzz is not and will not a Twitter clone. You may use it one day as often as u do with Twitter! Thanks guys!
Great tut. Google Buzz have to show us yet if it’s a revolution or just a clone. Cheers
.-= Shurandy Thode´s last blog ..Illustrator tips Part 1: Basic shapes, layering and sketch to vector =-.
Nice tip! Now I need to decide on whether I should put forth my tweets (as it is now) or should I change it to Google Buzz instead? (They’re both synced anyway!)
.-= Firdouss´s last blog ..Want a prettier facebook? Try the Microsoft Silverlight 4 client for facebook! =-.
You will find solution to combine Twitter and Google Buzz together. Just wait!
Thanks for this nice tutorial.
Great article! I really need to go check Google Buzz out. I keep saying I will but I keep putting it off … too many things out there .. aaarrrrgghh!
.-= Sneh Roy´s last blog ..20 Free Fonts Perfect For Fancy Logos =-.
Thanks Sneh
It took Twitter around 1 year to get popular, cause people didn’t see how these short messages can be useful. Gradually, many services were built on top of Twitter.
Now we all know about micro-blogging. So, it took Google Buzz around 1 day to get us interested
.-= Mike More´s last blog ..Google Buzz Widget – A jQuery Plugin =-.
Great
Does anyone know Google Buzz query string? Can we search Google Buzz without login to Gmail?
.-= Malaysia SEO´s last blog ..Don’t Waste Time On Creating Tags For Your Blog =-.
I don’t think so right now. I think you must be logged in.
I have error: “$ is not a function”
Here
$(document).ready(function(){
getGoogleBuzz(‘mikedotmore’, 5, $(‘#my-buzz’));
});
do you have google buzz button for wp ??
.-= mujecks´s last blog ..Islam Agamaku, Jilbab Identitasku =-.
will try this….
This is so cool
But th demo page is not working !
.-= Äạt Tà i´s last blog ..Chiến Thuáºt Khai Cuá»™c trong Cá» Vua =-.
Check out this site, it uses jQuery to pull your buzz http://buzz.matterr.com
Nice informative posting ! Thank you for sharing this !
Actually i am not familiar with programing site in web technology but in the tutorial is written by easily so that i feel interest Google Buzz. I hope in future i will apply the code for implementing Google Buzz.
Someone can use this to create a Google Buzz widget. Thanx!
Nice jquery with CSS tutorial. Thanks to help me to create google buzz widget for my blog.
It is a good way that anyone can easily to create something.
Great article. simply love this. A very useful post. Hope to read more like this.
I’m Very grateful to know this.How to Pull Your Google Buzz with j Query.
Thanks for sharing.