Download presentation
Presentation is loading. Please wait.
Published byShanon Bryan Parker Modified over 8 years ago
1
Activities in OpenSocial CS 195.35: Survey of Contemporary Technologies
2
Activities Actions carried out in a social application Activities are typically posted in an updates page in your container The OpenSocial API enables posting of activities and reading from a user’s activity stream (assuming the viewer is authorized to do so)
3
opensocial.Activity Class that represents an Activity object opensocial.newActivity(params) returns a new instance of Activity params is an array that indicates activity details (title, body, etc) Methods: getField( key ): returns a value setField( key, value): sets field to value Possible values for key: ‘title’, ‘body’, etc.
4
Posting an activity opensocial.requestCreateActivity(a,p,f) a: Activity object p: priority (‘high’ or ‘low’) f: callback function once request has been processed (can be used to refresh container webpage)
5
Example var count = 0; function postActivity() { alert("about to post activity"); var title = 'this is activity post: ' + ++count; var params = {}; params[opensocial.Activity.Field.TITLE] = title; var activity = opensocial.newActivity(params); opensocial.requestCreateActivity(activity, 'high', function() { alert("activity posted; count="+count); }); alert("activity post request sent"); } Click on this button to post an activity:
6
Reading from an activity stream An Activity stream can be requested through a DataRequest object newFetchActivitiesRequest(idspec) creates the request item idspec: specifies from which people to fetch activities Note: actual data will be retrieved and handled within the callback function when processed, a Collection object is returned
7
Example function loadActivities() { var req = opensocial.newDataRequest(); var person = opensocial.newIdSpec({ "userId" : "VIEWER"}); req.add(req.newFetchActivitiesRequest(person), 'acts'); req.send(onLoadActivities); } function onLoadActivities(data) { var myActs = data.get('acts').getData(); var html = ‘ '; myActs.each(function(activity) { html += gadgets.util.unescapeString(activity.getField('title')); html += ' '; }); document.getElementById('acts').innerHTML = html; }
8
About activities The OpenSocial API supports activities so that apps may generate app messages to be posted in a container, visible to the user and the user’s friends Currently supported differently by the different containers Authorization (e.g., friendster allows activity stream reading, orkut and igoogle do not, by default; orkut and igoogle allow posting, friendster does not) Rendering of activity content Try out the two sample applications out on your respective containers version 5 of the gift giving application from the opensocial tutorial (wiki.opensocial.org)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.