MySpace Developer Platform

A Place For Developers
From MySpace Open Platform: Documentation Wiki

Activity Templates

Jump to: navigation, search
Content
Content > Documentation > Walkthroughs
Content > MySpace Apps
Content > MySpace Apps > OpenSocial
Content > MySpace Apps > REST > Messaging > Activities > App Activities


Contents

Introduction

This document details the instructions on how to use Activity Templates to create activities.

Additional information is available for Activities Stream Spec Compliant Activities.

Activities Template Defined

The Activities Template is divided into five sections. These sections allow you to generate sample JavaScript code for activities that you can paste directly into your application. The five sections are described below:

  1. Content - This section allows you to define the content text to display on the member's activity feed.
  2. Variables - Define the variables created in the content section. These variables are further defined here as either person or literal.
  3. Media Items - This section is auto populated with images from your developer account. These images can be embedded into the activity.
  4. Preview - This section allows you to see how the activity displays to members on their activity feed.
  5. Sample JavaScript code - This section contains sample JavaScript code that is auto generated as you define the content, variables and media described above. You can paste this code directly into your application.

Note: the Variables section displays only after you define a variable in the Title or Body fields of the content section.


Within the Content section, the following two entry forms are availble:

  1. Single Form -When text and varibles are defined in this view, sample JavaScript code is auto-generated to display a member's single activity on the activity feed.
  2. Aggregate Form - When text and varibles are defined in this view, sample JavaScript code is auto-generated to describe members who perform multiple activities in one day. You can further group these activities by the variables defined in the Content and Variables sections described above.

How to Use the Activities Template

This section details the walk through instructions to use the Activities Template.

Create Template

From the top navigation bar:

1. Click on MyApps.

Developer Toolbar
Developer Toolbar




Your application listing displays:

Developer Application Listing
Developer Application Listing




2. Click on the Templates link of the application where you want to create activities.

Template Link
Template Link

Template Link


The New Activity Template prompt screen displays.


3. To create a template, click the Create Template or Create one now link.

New Template Prompt Screen
New Template Prompt Screen




The full activity template displays:

Full Activity Template
Full Activity Template




4. Create a name for your template and click the Save Template button.

Create Single Event Activity Using Single Form

This section details how to create the content for your activities. The content section has two tabs so that you can generate sample code for both single and multiple user activities.

To create a single activity, click on the Single Form tab. This tab is selected by default.

Content Section - Single Form Tab
Content Section - Single Form Tab




You can create any text you like for your activity title and select images from your developer account to add to the activity. Once you create the activity text and add an image, you can preview how the activity will display in the Preview window. View the screen shot below to see the four steps to generate the code for a single, simple activity.

  1. Enter content for the first activity:
    1. Enter template name.
    2. Add activity text after the ${subject} in the Title field.
      ${subject} has done something new!
  2. Select a media image. These images are populated from your developer account. (Optional).
  3. View how the activity displays in the Preview window.
  4. Copy the sample JavaScript code into your application.
Image:Mdp_activities_07.png
Image:Mdp_activities_07.png



For example: The member generating the activity is the ${subject}. Adding the text "has done something new!" after the ${subject} displays the following after clicking the Preview Template button. The sample code auto generates into the sample code box.

Image:Mdp_activities_07.png
Image:Mdp_activities_07.png



Adding New Variables

You can add and define new variables for activities simply by creating and naming them in the content section. Once you create a new variable and save the template, a new section titled Variables displays above the Media Item section.

Image:Mdp_activities_08.png
Image:Mdp_activities_08.png



The Variables section reveals when a new variable is defined in the Content section. Define a new variable by simply naming it inside of: ${ }.

Example: ${friend}

Image:Mdp_activities_09.png
Image:Mdp_activities_09.png

Variable Options



Variables can be further defined by type:

  • Literal - Enter the exact text that you would like displayed in the Test Value field.
  • Person - Enter the person ID into the Test Value field.
  • No Variable - Variables are not required in the template to create an activity.

Literal Example

Title
${subject} 1 Jolly Roger to ${literal_expression}!
Variable
When you add ${literal_expression} as a variable, the variable section of the template reveals and allows you to choose whether or not the ${literal_expression} variable is person or literal. This example uses a literal value. You must then put in the exact text you expect the member to see.
Media Items
Select a media icon (if desired) to add to your activity. (This is optional).
Preview
Click Preview Template to see how your activity will appear to members.
Sample JavaScript code
Copy the sample code into your application.
Image:Mdp_activities_11.png
Image:Mdp_activities_11.png



Person Example

Title
${subject} gives 1 cute kitty to ${memberid}!
Variable
When you add ${memberid} as a variable, the variable section of the template reveals and allows you to choose whether or not the ${memberid} variable is person or literal. This example uses a person value. You must then put the member ID into the test value field.
Media
Select a media icon (if desired) to add to your activity. (This is optional).
Preview
Click the Preview Template button to see how your activity will appear to members.
Sample JavaScript code
Copy the sample code into your application.
Image:Mdp_activities_10.png
Image:Mdp_activities_10.png



No Variable Example

Title
${subject} gives this application 1 Jolly Roger!
Variable
Without adding a ${variable} – The variable section of the template does not display.
Media Items
Select a media icon (if desired) to add to your activity. (This is optional).
Preview
Click the Preview Template button to see how your activity will appear to members.
Sample JavaScript code
Copy the sample code into your application.
Image:Mdp_activities_12.png
Image:Mdp_activities_12.png



Create Multiple Activities Using Aggregate Form

To describe multiple activity events in one day in plural form, use the Aggregate Form tab. Creating multiple activities is similar to creating a single activity. To use the Aggregate Form, the Single Form must be defined.


1. From the Template Editor, click on the Aggregate Form tab.

Image:Mdp_activities_13.png
Image:Mdp_activities_13.png




2. Un-check the Use Single Form definition checkbox.

Image:Mdp_activities_14.png

This unlocks the Title and Body fields so text can be entered into the form.


3. Enter the Title and Body content for the activity in plural form.

Example: ${subject} is taking multiple forms of transport.

Image:Mdp_activities_15.png
Image:Mdp_activities_15.png




4. Add multiple test values for one of the variables by clicking on add next to the first Test Value then click on the Preview Template button.

Image:Mdp_activities_16.png
Image:Mdp_activities_16.png




5. View how the activity displays in the Preview window. Single and Aggregate content is displayed in the Preview window at the same time.

Image:Mdp_activities_17.png
Image:Mdp_activities_17.png




6. Copy the sample JavaScript code into your application.

Image:Mdp_activities_18.png
Image:Mdp_activities_18.png



How to Raise an Activity in an Application

After an event is created using the Template Editor, preview the event in the editor. The Template Editor will create the JavaScript required to raise the event in your application.

Copy and paste this JavaScript from the Template Editor into your application code in order to raise the event in your application.

Restrictions

What restrictions apply to a Template?

  • For templates that have been published and are now Live, only text changes can be made. You cannot add new variables nor change the name of the template.
  • Variables are restricted to a maximum of 60 visible characters.
  • Variables may be entered in the Title and Body sections of a Template.
  • Variables in the Template Editor always take the form ${variable_name}.
  • The Title section of a template must be non-null, and must contain the System variable ${subject} to identify the user who performs an activity or causes an event to be raised.
  • Both System Variables and User-Defined variables may be used to define an activity.
  • A maximum of four variables may be defined in a template.
  • User-defined variables in a template must be alpha characters in the range [a-z].
  • No polymorphism is allowed with system variables – they may not be overloaded.
  • A maximum of three media items per activity update is supported.

System Variable Restrictions

System Variables are restricted to the following:

  • ${subject} – the user who caused the activity or event.
  • ${canvasUrl} – expands to the URL of the canvas page of your application.
  • ${subject.DisplayName} – displays only the name of the user who caused an activity or event.
  • ${subject.Id} – displays the ID of the user who caused an activity or event.
  • ${subject.ProfileUrl} – displays the profile URL of the user who caused an activity or event.
  • ${yourVariable.Count} – displays the number of events occurring in one day on the template.

Template Title Restrictions

The Title section of a template has the following restrictions:

  • It must contain the system variable ${subject} to identify the user raising an event.
  • It may contain a maximum of 160 visible characters.
  • It may contain the following subset of HTML tags: <a>, <i>, <em>, <u>, <b>, <strong>

All <a> tags must resolve to the http://*.myspace.com domain.

Template Body Restrictions

The Body section of a template has the following restrictions:

  • It may contain a maximum of 260 visible characters.
  • It may contain associated images if they have been defined and are in a public photo album.
  • It may contain a subset of HTML tags: <a>, <i>, <em>, <u>, <b>, <strong>, <br/>

All <a> tags must resolve to the http://*.myspace.com domain.

Release Updates

As of April 7, 2009:

  • External links are allowed on the activity feed.

As of December 17, 2008:

  • Developers can publish activity templates.
  • Users can raise activity template events (if their application has the OpenSocial 0.8 container active).
  • Users can see activity events from their friends if they both have the app installed on the User Home Page.
  • Users can see their own activity events in the friend update page.

Related Links