Google+ のアクティビティ API を使用できます。これは現在、公開投稿に制限されていますが、始めるには十分なはずです。プロファイル ID は、ユーザーのプロファイルから取得されます。検索 API など、このコンテンツを取得する方法は他にもあります。
さまざまな言語のドキュメントと簡単な例は、Google プラス ページ (https://developers.google.com/+/api/latest/activities) で見つけることができます。次の JavaScript の例は、動作の仕組みを理解するのに役立ちます。
// globals used for auth, showing debugging
var debug = true;
var key = "your api key from https://code.google.com/apis/console";
function handleRequestIssue(request){
// For now, just show the error
console.log("Error, status:" + request.status + " / response:" + request.responseText);
}
function performXHR(URL){
var objReturn = "";
var request = new XMLHttpRequest();
request.open('GET', URL, false);
request.send(); // because of "false" above, will block until the request is done
// and status is available. Not recommended, however it works for simple cases.
if (request.status === 200) {
if (debug) console.log(request.responseText);
var objReturn = jQuery.parseJSON(request.responseText).items;
if (debug){
for (value in objReturn){
console.log(value);
}
}
}else{
handleRequestIssue(request);
}
return objReturn;
}
// Gets the activities for a profile
function getActivities(profileID){
var activities = null;
var URL = "https://www.googleapis.com/plus/v1/people/" + profileID + "/activities/public?alt=json&key=" + key;
activities = performXHR(URL);
console.log(activities.length);
return activities;
}
この時点で、デバッガーでアクティビティを確認できます。div などの内部で常にコンテンツを HTML としてレンダリングできます。
function renderActsComments(activities, identifier, filter){
var renderMe = "";
console.log("activities retrieved: " + activities.length);
for (var i=0; i < activities.length; i++) {
var render = true;
console.log("trying to do something with an activity: " + i);
var activity = activities[i];
if (filter != null && filter.length > 0){
if (activity.crosspostSource.indexOf(filter) == -1){
render = false;
}
}
if (render == true){
renderMe += "<br/><div class=\"article\"><p>" + activity.title + "</p>";
console.log(activity.id);
// get comments
var comments = getCommentsForActivity(activity.id);
var left = true;
for (var j=0; j<comments.length; j++){
if (left){
left = false;
renderMe += "<br/><p class=\"speech\">" + comments[j].object.content + "</p>";
renderMe += "<a href=\"" + comments[j].actor.url + "\">" + comments[j].actor.displayName + "</a>";
renderMe += "<a href=\"" + comments[j].actor.image.url.replace(/\?.*/, "") + "\">";
renderMe += " <img border=0 src=\"" + comments[j].actor.image.url + "\"/></a>";
renderMe += "</p>";
}else{
renderMe += "<br/><p class=\"speechAlt\">" + comments[j].object.content + "</p>";
left = true;
renderMe += "<p class=\"profileAlt\">";
renderMe += "<a href=\"" + comments[j].actor.image.url.replace(/\?.*/, "") + "\">";
renderMe += "<img border=0 src=\"" + comments[j].actor.image.url + "\"/></a>";
renderMe += "<a href=\"" + comments[j].actor.url + "\"> " + comments[j].actor.displayName + "</a>";
renderMe += "</p>";
}
}
renderMe += "</div>";
}
}
console.log("I'm done");
document.getElementById(identifier).innerHTML = renderMe;
return renderMe;
}