Google+ user post archive
by Peteris
JavaScript
/*
Google+ API Experiment: Creates a blogesque archive of a user's public posts.
by Peteris Erins (@P_E, peteriserins.com[/+])
Note: To run this, you will need an API key. Go here https://code.google.com/apis/console#access to do that. The current daily API limit is 1000 so please do not try to crawl users with 20000 posts just yet :).
*/
// Target user id goes here (as a string)
var id = '115771747876881317181';
// Your API access key goes here
var key = 'please fill this in with your API key; see above for instructions';
var items = [];
(function crawl(token){
var request = 'https://www.googleapis.com/plus/v1/people/' + id + '/activities/public?key=' + key;
// We select only the fields we need
// Setting the callback variable is required for JSONP two work
request += '&fields=nextPageToken,items(title,url,published)&callback=?';
// We're setting the pageToken to request the next page of results
request += (token == undefined ? '' : '&pageToken=' + token);
$.getJSON(request, function(json){
if (!('items' in json)){
construct();
}else{
items = items.concat(json.items);
crawl(json.nextPageToken);
}
})
})();
// Simple HTML table construction
function construct(){
var archive = $('<table>');
for (var i = 0; i < items.length; ++i){
var row = $('<tr>');
var link = $('<a>');
link.attr('href', items[i].url).html(items[i].title);
row.append($('<td>').append($('<span>').html(items[i].published.substr(0, 10))));
row.append($('<td>').append(link));
archive.append(row);
}
$('body').prepend(archive);
}