1 / 8

Activities in OpenSocial

Activities in OpenSocial. CS 195.35: Survey of Contemporary Technologies. Activities. Actions carried out in a social application Activities are typically posted in an updates page in your container

cespedes
Download Presentation

Activities in OpenSocial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Activities inOpenSocial 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 <script type="text/javascript"> 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"); } </script> <br> Click on this button to post an activity: <input type="button" name="myButton“ value="Post" onclick="postActivity();" />

  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<Activity> 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 = ‘<p>'; myActs.each(function(activity) { html += gadgets.util.unescapeString(activity.getField('title')); html += '<p>'; }); 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)

More Related