Representation of an activity.
Activities are rendered with a title and an optional activity body.
You may set the title and body directly as strings when calling opensocial.createActivity.
However, it is usually beneficial to create activities using Activity Templates for the title and body. Activity Templates support:
Activity Templates are defined as messages in the gadget specification. To define messages, you create and reference message bundle XML files for each locale you support.
Example module spec in gadget XML:
<ModulePrefs title="ListenToThis"> <Locale messages="http://www.listentostuff.com/messages.xml"/> <Locale lang="de" messages="http://www.listentostuff.com/messages-DE.xml"/> </ModulePrefs>
Example message bundle:
<messagebundle>
<msg name="LISTEN_TO_THIS_SONG">
${Subject.DisplayName} told ${Owner.DisplayName} to
listen to a song!
</msg>
</messagebundle>
You can set custom key/value string pairs when posting an activity. These values will be used for variable substitution in the templates.
Example JS call:
var owner = ...;
var viewer = ...;
var activity = opensocial.newActivity('LISTEN_TO_THIS_SONG',
{Song: 'Do That There - (Young Einstein hoo-hoo mix)',
Artist: 'Lyrics Born', Subject: viewer, Owner: owner})
Associated message:
<msg name="LISTEN_TO_THIS_SONG">
${Subject.DisplayName} told ${Owner.DisplayName} to listen
to ${Song} by ${Artist}
</msg>
People can also be set as values in key/value pairs when posting an activity. You can then reference the following fields on a person:
Users will have many activities in their activity streams, and containers will not show every activity that is visible to a user. To help display large numbers of activities, containers will summarize a list of activities from a given source to a single entry.
You can provide Activity Summaries to customize the text shown when multiple activities are summarized. If no customization is provided, a container may ignore your activities altogether or provide default text such as "Bob changed his status message + 20 other events like this."
Example summaries:
<messagebundle>
<msg name="LISTEN_TO_THIS_SONG:Artist">
${Subject.Count} of your friends have suggested listening to songs
by ${Artist}!
</msg>
<msg name="LISTEN_TO_THIS_SONG:Song">
${Subject.Count} of your friends have suggested listening to ${Song}
!</msg>
<msg name="LISTEN_TO_THIS_SONG:Subject">
${Subject.DisplayName} has recommended ${Song.Count} songs to you.
</msg>
</messagebundle>
Activity Templates may only have the following HTML tags: <b>, <i>, <a>, <span>. The container also has the option to strip out these tags when rendering the activity.
See also: opensocial.newActivity(), opensocial.requestCreateActivity()
String
getField(key)
String
getId()
setField(key, data)
String getField(key)
String key - The key to get data for;
see the Field class
for possible values
String The data
String getId()
String The ID
setField(key, data)
String key - The key to set data for
String data - The data to set