Application activity events from your friends will be shown on your Home Page and on your Friend Update page. Your Home Page will show a maximun of 50% of application events, and you will compete for this real estate with your fellow application developers. There is not much control you have in this area.
You can also retrieve your events from your own application and show this on the application canvas page or on the profile page. Here is a little code sample that uses some jQuery to render the results:
<span id="status"></span>
<form>
<fieldset>
<label for="whom">Get application events for </label>
<input type="radio" name="whom" value="viewer" checked="true"/>viewer<input type="radio" name="whom" value="owner" />or owner
<label for="justMyEvents">; show my events only</label>
<input type="checkbox" name="justMyEvents" value="true" />
</fieldset>
</form>
<div id="activiesFeed">.</div><div id="feedTxtToHtml">.</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script>
function getActivities(){
$("#activiesFeed").html("");
var showViewer = $("input[@name=whom]:checked").val() == 'viewer';
var justMyEvents = $("input[@name=justMyEvents]:checked").val() == 'true';
var idspec = opensocial.newIdSpec();
if (showViewer) {
idspec.setField(opensocial.IdSpec.Field.USER_ID, opensocial.IdSpec.PersonId.VIEWER);
} else {
idspec.setField(opensocial.IdSpec.Field.USER_ID, opensocial.IdSpec.PersonId.OWNER);
}
if (justMyEvents) {
idspec.setField(opensocial.IdSpec.Field.NETWORK_DISTANCE, 0);
} else {
idspec.setField(opensocial.IdSpec.Field.NETWORK_DISTANCE, 1);
} var dataRequest = opensocial.newDataRequest();
dataRequest.add(dataRequest.newFetchActivitiesRequest(idspec, "activity"));
dataRequest.send(processActivities);
}
function processActivities(response){
try {
var activitiesData = MyOpenSpace.RequestType.FETCH_ACTIVITIES;
if (response.hadError() || response.get(activitiesData).hadError()) {
if (response.get(activitiesData).getErrorCode() == opensocial.ResponseItem.Error.UNAUTHORIZED) {
$("#status").html("Unauthorized; requesting user for permission.");
requestUserToReceiveActivities();
return;
}
if (response.get(activitiesData).hadError()) {
$("#status").html("Error getting activities");
$("#status").append(response.get(activitiesData).getErrorCode());
$("#status").append(response.get(activitiesData).getErrorMessage());
}
$("#status").append(response.getErrorMessage());
} else {
var receivedData = response.get(activitiesData).getData();
$("#activiesFeed").append("<ol>");
for (var item in receivedData.asArray()) {
var timeTxt = receivedData.asArray()[item].getField("postedTime");
// note: iconUrl is missing, but that would just be your regular icon for the app.
var iconUrl = receivedData.asArray()[item].getField("streamFavIconUrl");
var userId = receivedData.asArray()[item].getField("userId");
var titleId = receivedData.asArray()[item].getField("titleId");
var appId = receivedData.asArray()[item].getField("appId");
var titleTxt = receivedData.asArray()[item].getField("title");
var bodyTxt = receivedData.asArray()[item].getField("body");
var oneUpdate = "";
if (bodyTxt != null && bodyTxt.length > 0){
oneUpdate = "<li> on " + timeTxt.substring(0,16) + ": <div>" + $("#feedTxtToHtml").html(titleTxt).text() + "<br/>" + $("#feedTxtToHtml").html(bodyTxt).text() + "</div></li>";
} else {
oneUpdate = "<li> on " + timeTxt.substring(0,16) + ": <div>" + $("#feedTxtToHtml").html(titleTxt).text() + "</div></li>";
}
$("#activiesFeed").append(oneUpdate);
}
$("#activiesFeed").append("</ol>");
//make sure all hyperlinks get out of the iframe
$("#activiesFeed a").attr("target", "_blank");
//hide the helper dom object.
$("#feedTxtToHtml").hide();
}
}
catch (any){
$("#status").html("<span style='color:red'>ERROR with rendering the feed.</span>");
}
}
function requestUserToSentActivities(){
opensocial.requestPermission([MyOpenSpace.Permission.VIEWER_SEND_UPDATES_TO_FRIENDS], "Let your friends know what you are doing.", checkPermissionResponseSent);
}
function requestUserToReceiveActivities(){
opensocial.requestPermission([MyOpenSpace.Permission.VIEWER_SHOW_UPDATES_FROM_FRIENDS], "See what your friends are doing with this app!", checkPermissionResponseReceive);
}
function checkPermissionResponseSent(){
//This does get called, but don't use alert statements. They are filtered by the container
}
function checkPermissionResponseReceive(){
//This does get called, but don't use alert statements. They are filtered by the container
}
</script>