Home / Archive by category 'Social Apps'

Social Apps

Opensocial.requestCreateActivity()

Opensocial.requestCreateActivity()

Description:
Makes a request to the container to create the activity. Parameters include activity (instance of opensocial.Activity), p (priority, specified by opensocial .CreateActivityPriority.HIGH or LOW), and opt_callback (optional callback function to be called when activity is created).

Object:
Opensocial


Opensocial.newNavigationalParameters()

Opensocial.newNavigationalParameters()

Description:
Redirects the user. Parameters include p (parameter map keyed with opensocial.NavagationalParameters.Field.* values that specify where to navigate to and when).

Returns:
opensocial.NavagationalParameters

Object:
Opensocial


Opensocial.newMessage()

Opensocial.newMessage()

Description:
Creates a new message. Parameters include body (string, message) and opt_params (optional parameters, keyed with opensocial.Message.Field.*).

Returns:
opensocial.Message

Object:
Opensocial


Opensocial.newMediaItem()

Opensocial.newMediaItem()

Description:
Creates a media item. Parameters include mt (type of media, specified by opensocial.MediaItem.Field.*), url (location of media, a string), and opt_params (optional parameters specifying additional fields).

Returns:
opensocial.MediaItem

Object:
Opensocial

Example:

var myVideo = opensocial.newMediaItem(opensocial.MediaItem.Field.VIDEO,"http://w3mentor.com/Video.mpg")

Opensocial.newIdSpec()

Opensocial.newIdSpec()

Description:
Creates a new instance of the DataRequest class with which to make data requests

Returns:
opensocial.IdSpec

Object:
Opensocial


Opensocial.newDataRequest()

Opensocial.newDataRequest()

Description:
Creates a new instance of the DataRequest class with which to make data requests

Returns:
opensocial.DataRequest

Object:
Opensocial

Example:

dataReqObj = opensocial.newDataRequest();

Opensocial.newActivity()

Opensocial.newActivity()

Description:
Creates a new instance of opensocial.Activity. Parameters specifying the activity include items such as title, body, and more.

Returns:
opensocial.Activity

Object:
Opensocial


Opensocial.hasPermission(p)

Opensocial.hasPermission(p)

Description:
Tells if application has permission.
Returns:
a Boolean.Parameters include p (an instance of opensocial.Permission).
Object:
Opensocial


Opensocial.getEnvironment()

Opensocial.getEnvironment()

Description:
Obtains the Environment associated with your application.
Returns:
opensocial.Environment
Object:
Opensocial


Display a Drop-down List of Viewer’s Friends in Open Social

Complete example to Display a Drop-down List of Viewer’s Friends in Open Social

var dataReqObj;
var heading = ‘’;
var friends_html;
var TheFriends = new Array();
//function called initially in XML file, this makes data request
//for friend.
 
 
function init() {
    //Create Data Request
    dataReqObj = opensocial.newDataRequest();
    //create viewer request
    var viewerReq = dataReqObj.newFetchPersonRequest(opensocial.IdSpec.
    PersonId.VIEWER);
    dataReqObj.add(viewerReq, ‘viewer’);
    // create friends of viewer request
    var idspec = opensocial.newIdSpec({
        "userId": "VIEWER",
        "groupID": "FRIENDS"
    });
    viewerReq = dataReqObj.newFetchPeopleRequest(idspec);
    dataReqObj.add(viewerReq, ‘viewerFriends’);
    //Send Data Request
    dataReqObj.send(onLoadViewerResponse);
}
//Callback function to process Viewer data requested.
 
 
function onLoadViewerResponse(data) {
    var viewer;
    //retrieve data associated with viewer request.
    try {
        viewer = data.get(’viewer’).getData();
    } catch (err) {
        heading = ‘Error‘ + err.description;
        alert(heading);
    }
    //Set up html to return to display viewer basic info
    try {
        var thumb = viewer.getField(opensocial.Person.Field.THUMBNAIL_URL);
        var profile = viewer.getField(opensocial.Person.Field.PROFILE_URL);
        heading = heading +< a href = "’ + profile +’" > < img src = "’ + thumb +
‘" > < /a>;
} catch(err){
heading = ‘Error ‘ + err.description;
alert(heading);}
document.getElementById(’heading’).innerHTML = heading;
/ / Get Friends Information
        var viewer_friends = data.get(’viewerFriends’).getData();
        friends_html = ‘Your Friend,;
        friends_html = friends_html +< select id = select_friend
        onchange = "getFriendStatus();" >;
        viewer_friends.each(function (person) {
            friends_html = friends_html +< option value =+ person.getId() +>+ person.getDisplayName() +< /option>;
TheFriends[person.getId()] = person;
});
friends_html = friends_html +</select >;
            document.getElementById(’friends’).innerHTML = friends_html;
        }

Request and Display Basic Viewer Data in Open Social

Step 1. Request data:
a. Create DataRequest object by calling opensocial.newDataRequest.
b. For each request you wish to make, create it using one of the opensocial.new* methods.
c. For each piece of data you want to request, add a request via DataRequest.add(request).
d. Make a request by registering the callback function, DataRequest.send(callback).

Step 2. Create a callback function to receive data:
a. Once a container gets the request and it is processed, the callback function will be executed. It will be passed the opensocial.DataResponse object that contains the response data of the processed request. In the following code example, the DataResponse object is received as a parameter to the callback function, and is called dataResponse:

function callback(dataResponse) {
//process the response data
}

Complete Example:

var dataReqObj;
var heading = ‘’;
//function called initially in XML file, this makes data request
//for viewer
function init() {
    //Create Data Request
    dataReqObj = opensocial.newDataRequest();
    //depending of version of OpenSocial, viewer reference changes
    var viewerReq = dataReqObj.newFetchPersonRequest
    ( opensocial.IdSpec.PersonId.VIEWER);
    dataReqObj.add(viewerReq, ‘viewer’);
    //Send Data Request
    dataReqObj.send(onLoadViewerResponse);
}
//Callback function to process Viewer data requested.
function onLoadViewerResponse(data) {
    var viewer;
    //retrieve data associated with viewer request.
    try{
        viewer = data.get(’viewer’).getData();
        }catch(err){
        heading = ‘Error ‘ + err.description;
    alert (heading);}
    //Setup html to return to display viewer basic info
    try{
        heading = ‘Hello,+ viewer.getDisplayName();
        var thumb =
        viewer.getField(opensocial.Person.Field.THUMBNAIL_URL);
        var profile =
        viewer.getField(opensocial.Person.Field.PROFILE_URL);
        heading = heading +<a href="’ + profile +’">&lt;img src="’
        + thumb
        + ‘"&gt;</a>;
        } catch(err){
        heading = ‘Error ‘ + err.description;
    alert(heading);}
    //Display results inside XML document at the div
    //element with id heading
    document.getElementById(’heading’).innerHTML = heading;
}

Types of users in Open Social

Owner — This is the person who owns the account and has installed your application. Depending on container support, this can be specified with the string ‘OWNER’, opensocial.DataRequest.PersonId.OWNER, or opensocial.IdSpec.PersonId.OWNER. The latter is the accepted standard for the latest version of OpenSocial.

Viewer — A viewer is a person logged in to the social network who can be viewing either that person’s own page that has your application on it, or another user’s page that has your application on it. Depending on container support, this can be specified with the string ‘VIEWER’, opensocial.DataRequst.PersonId.VIEWER, or opensocial.IdSpec.PersonId.VIEWER. (The latter
is the latest version of OpenSocial.)

Friends — Friends appear in the social network as either the owner or viewer.


Multiple content tags in Open Social applications

<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Another Multiple Views Example">
    <Require feature="opensocial-0.8"/>
  </ModulePrefs>
  <Content type="html" view="home"><![CDATA[
<h1>Home</h1>
]]></Content>
  <Content type="html" view="profile"><![CDATA[
<h1>Profile</h1>
]]></Content>
  <Content type="html" view="canvas"><![CDATA[
<h1>Canvas</h1>
]]></Content>
  <Content type="html" view="canvas,profile"><![CDATA[
I am in both the canvas and profile view but, NOT in the home view.
]]></Content>
  <Content type="html"><![CDATA[
I am in any view that is not specified. (the preview view)
]]></Content>
</Module>

Multiple views in Open Social applications

<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Multiple Views Example">
    <Require feature="opensocial-0.8"/>
  </ModulePrefs>
  <Content type="html" view="profile"><![CDATA[
<h1>Profile Content</h1>
]]></Content>
  <Content type="html" view="canvas"><![CDATA[
<h1>Canvas Content</h1>
]]></Content>
</Module>

Other Combinations:

<Content views="canvas, home">

This means the contained content will be displayed for both ‘‘canvas’’ and ‘‘home’’ views.

<Content>

This will be the default content displayed for all views not specified with a views=”XX” tag.

<Content views="profile">

If this is the only content tag in your XML application, it means that the application will only be shown in the user’s profile and not other possible views.


Adjust the Height of an Open Social application

<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Hello World!" description="Hello World" title_url="http://www.hi5.com" author="w3mentor" author_email="w3mentor@w3m.com" author_affiliation="w3mentor" author_location="usa" thumbnail="http://w3mentor.com/Logo.png">
    <Icon>http://w3mentor.com/Logo-16x16.png</Icon>
    <Require feature="dynamic-height"/>
    <Require feature="opensocial-0.8"/>
  </ModulePrefs>
  <Content type="html"><![CDATA[
Hello World!
<script>
// Call the init function onLoad
gadgets.util.registerOnLoadHandler(init);
function init() {
gadgets.window.adjustHeight(50);
}
</script>
]]></Content>
</Module>

Feature-Specific API objects in Open Social

gadgets.views — Views
gadgets.window — Window
gadgets.skins — Skins
gadgets.flash — Flash
gadgets.MiniMessage — Minimessage
gadgets.Tab — Tabs
gadgets.TabSet — Tabs
gadgets.pubsub — Publishing (Subscribing)
gadgets.rpc — RPC


Detect user’s language in Open Social applications

<?xml version="1.0" encoding="UTF-8"?>
<Module>
   <ModulePrefs title="Hello World!" description="Hello World" title_url="http://www.hi5.com" author="w3mentor" author_email="w3mentor@w3m.com" author_affiliation="w3mentor" author_location="usa" thumbnail="http://w3mentor.com/Logo.png">
    <Icon>http://w3mentor.com/Logo-16x16.png</Icon>
    <Require feature="opensocial-0.8"/>
  </ModulePrefs>
  <Content type="html"><![CDATA[
Hello World!
<div id="greeting" style="background: red;">
</div>
<script>
// Call the init function onLoad
gadgets.util.registerOnLoadHandler(init);
// function to learn users language and display it.
function init() {
var lang = "Not Known ";
try{
var prefs = new gadgets.Prefs();
lang = prefs.getLang();
if (lang == null)
document.getElementById('greeting').innerHTML = "lang is
null"
else
document.getElementById('greeting').innerHTML = "lang is " + lang;
}catch (e) {
document.getElementById('greeting').innerHTML = "exception";}
}
</script>
]]></Content>
</Module>

Advanced Hello World in Open Social

<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Hello World!" description="Hello World" title_url="http://www.hi5.com" author="w3mentor" author_email="w3m@w3mentor.com" author_affiliation="w3m" author_location="USA" thumbnail="http://w3mentor.com/Logo.png">
    <Icon>http://Me.com/Logo-16x16.png</Icon>
    <Require feature="opensocial-0.8"/>
  </ModulePrefs>
  <Content type="html"><![CDATA[
Hello, world!
]]></Content>
</Module>

ModulePrefs Elements and Attributes

title
The short name associated with the application.
This attribute is required to create/update an application.
Minimum length is 1 character.
Maximum length is 64 characters.
Must use only the following characters: a-z, A-Z, 0-9, ‘,&, !, ., -, _, ?, [space].
Must start with a letter.

description
A short description of the application, used for display in the Gallery.
This attribute is required to create/update an application.
Minimum length is 1 character.
Maximum length is 256 characters.
Must use only the following characters: a-z, A-Z, 0-9, ‘,&, !, ., -, _, ?, [space].

thumbnail
The URL of the thumbnail image associated with the gadget. This is displayed in the App
Gallery, and the App Profile page.
Must point to a valid .gif, .png, or .jpg file.
Image dimensions must be 64 x 64 pixels.
File size must be less than 300KB.

height
Indicates the preferred height (in pixels) for the content.
This is optional, and the default is to use the default rendering height for the view surface.
Minimum value is 20.
Maximum value is 1000.


preferredHeight in content xml tag for open social

The following applies to

<Content preferredHeight="">

tag:
It Specifies the initial height desired for the surface. If not provided, then the height attribute from element is used. preferredHeight has a minimum value is 20 and a maximum value is 1000. If the preferredHeight is specified multiple times for the same view/surface, then the last one takes precedence.