Google+ public feed (JSON) with jQuery

With the release of the Google+ api I was tasked to see what it might look like if we pulled in a feed into our intranet. Below is the resultant code.

The trickiest part to the code is setting callback=? at the end of the url and setting the dataType to jsonp, the p is very significant check here why.

Please note you need to add your own google+ api key below
“YOURKEY” as well as your own google plus userID “YOURGOOGLEPLUSID”.

Contents of getGooglePlus.js below,
$(document).ready(function() {
$.ajax({
type: “get”,
url: “https://www.googleapis.com/plus/v1/people/YOURGOOGLEPLUSID/activities/public?alt=json&pp=1&key=YOURKEY&callback=?”,
contentType: “application/json; charset=utf-8″,
dataType: “jsonp”,
success: function(msg) {
BuildTable(msg);
}
});
});

function BuildTable(msg) {

var table = ‘

‘; for (var i = 0, l = msg.items.length; i < l; i++) { var googlePlus = msg.items[i];

var row = ‘
‘;row += ‘‘ + googlePlus.object.attachments[0].displayName + ‘
‘ + googlePlus.object.attachments[0].content + ‘

‘;
row += ‘

‘;
table += row;
}
table += ‘

‘;
$(‘#Container’).html(table);
}

Contents of HTML CODE:

<script src=”http://code.jquery.com/jquery-latest.js” >
<script src=”getGooglePlus.js”>
<div id=”Container”>

Follow

Get every new post delivered to your Inbox.