Activities in OpenSocial

8
Activities in OpenSocial CS 195.35: Survey of Contemporary Technologies

description

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 - PowerPoint PPT Presentation

Transcript of Activities in OpenSocial

Page 1: Activities in OpenSocial

Activities inOpenSocial

CS 195.35: Survey of Contemporary Technologies

Page 2: Activities in OpenSocial

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)

Page 3: Activities in OpenSocial

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.

Page 4: Activities in OpenSocial

Posting an activity

opensocial.requestCreateActivity(a,p,f)a: Activity objectp: priority (‘high’ or ‘low’) f: callback function once request has been

processed (can be used to refresh container webpage)

Page 5: Activities in OpenSocial

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();" />

Page 6: Activities in OpenSocial

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

Page 7: Activities in OpenSocial

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; }

Page 8: Activities in OpenSocial

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)