OpenSocial services supported for Friendster
 

a. People & Relationships

To access the information of the user who is interacting with the application, his profile and his relationships on the network
Following are the list of Opensocial APIs supported by this service.

1. newFetchPersonRequest (more)
2. newFetchPeopleRequest (more)

Following are the fields supported by the person object

1. opensocial.Person.Field.ID
2. opensocial.Person.Field.NAME
3. opensocial.Person.Field.THUMBNAIL_URL
4. opensocial.Person.Field.PROFILE_URL
5. opens ocial.Person.Field.ADDRESSES

5.1 opensocial.Address.Field.COUNTRY
5.2 opensocial.Address.Field.POSTAL_CODE
5.3 opensocial.Address.Field.REGION
5.4 opensocial.Address.Field.UNSTRUCTURED_ADDRESS
5.5 opensocial.Address.Field.TYPE

6. opensocial.Person.Field.ABOUT_ME
7. opensocial.Person.Field.GENDER
8. opensocial.Person.Field.RELATIONSHIP_STATUS
9. opensocial.Person.Field.DATE_OF_BIRTH
10. opensocial.Person.Field.MUSIC
11. opensocial.Person.Field.MOVIES
12. opensocial.Person.Field.TV_SHOWS
13. opensocial.Person.Field.BOOKS
14. opensocial.Person.Field.LOOKING_FOR
15. opensocial.Person.Field.INTERESTS
16. opensocial.Person.Field.SCHOOLS

16.1 opensocial.Organization.Field.NAME
16.2 opensocial.Organization.Field.START_DATE
16.3 opensocial.Organization.Field.END_DATE
16.4 opensocial.Organization.Field.ADDRESS (more)

 

              Example:
          
              <script type="text/javascript">

              function getData()
              {
                var opt_params = { };
                var req = opensocial.newDataRequest();
                opt_params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS]
                =[opensocial.Person.Field.PROFILE_URL,opensocial.Person.Field.ADDRESSES
                ,opensocial.Person.Field.ABOUT_ME];
                req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER
                ,opt_params), 'viewer');
                req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.
                VIEWER_FRIENDS,opt_params), 'viewerFriends');
                req.send(onLoadFriends);
             };

             function onLoadFriends(dataResponse)
             {
               var viewer = dataResponse.get('viewer').getData();
               var html = "";
               html += 'Id:: ' + viewer.getField(opensocial.Person.Field.ID)+"<br>";
               html += 'Name:: ' + viewer.getDisplayName()+"<br>";
               html += 'Profile URL:: ' + viewer.getField(opensocial.Person.Field.PROFILE_URL)
               +"<br>";
               html += 'ADDRESSESCountry::'+viewer.getField(opensocial.Person.Field.ADDRESSES)
               [0].getField(opensocial.Address.Field.COUNTRY)+"<br>";
               html +='ADDRESSES Postal code::'+viewer.getField(opensocial.Person.Field.ADDRESSES)
               [0].getField(opensocial.Address.Field.POSTAL_CODE)+"<br>";
               html += 'ADDRESSES region :: ' +viewer.getField(opensocial.Person.Field.ADDRESSES)
               [0].getField(opensocial.Address.Field.REGION)+"<br>";
               html += 'ADDRESSES type:: ' +viewer.getField(opensocial.Person.Field.ADDRESSES)
               [0].getField(opensocial.Address.Field.TYPE)+"<br>";
               html += 'ADDRESSES unstructuredAddress:: ' +	viewer.getField(opensocial.Person.Field
               .ADDRESSES)[0].getField(opensocial.Address.Field.UNSTRUCTURED_ADDRESS+"<br>";
               html += 'ABOUT_ME:: ' + viewer.getField(opensocial.Person.Field.ABOUT_ME)+"<br>";
               var viewerFriends = dataResponse.get('viewerFriends').getData();
               viewerFriends.each(function(person) 
               {
                 html += 'Id:: ' + person.getField(opensocial.Person.Field.ID)+"<br>";
                 html += 'Name:: ' + person.getDisplayName()+"<br>";
                 html += 'Profile URL:: ' + person.getField(opensocial.Person.Field.PROFILE_URL)+"<br>";
                 html += 'ADDRESSES Country:: ' + person.getField(opensocial.Person.Field
                 .ADDRESSES)[0].getField(opensocial.Address.Field.COUNTRY)+"<br>";
                 html += 'ADDRESSES Postal code:: ' + person.getField(opensocial.Person.Field
                 .ADDRESSES)[0].getField(opensocial.Address.Field.POSTAL_CODE)+"<br>";
                html += 'ADDRESSES region :: ' + person.getField(opensocial.Person.Field.ADDRESSES)[0]
                .getField(opensocial.Address.Field.REGION)+"<br>";
                html += 'ADDRESSES type:: ' + person.getField(opensocial.Person.Field.ADDRESSES)[0]
                .getField(opensocial.Address.Field.TYPE)+"<br>";
                html += 'ADDRESSES unstructuredAddress:: ' + person.getField(opensocial.Person.Field
                .ADDRESSES)[0].getField(opensocial.Address.Field.UNSTRUCTURED_ADDRESS	+"<br>";
                html += 'ABOUT_ME:: ' + person.getField(opensocial.Person.Field.ABOUT_ME)+"<br>";
              });
              document.getElementById('message').innerHTML = html;
            };
            gadgets.util.registerOnLoadHandler(getData);
           </script>
           <div id="message"< </div>
						
 

b. Activities

To interact with user's activities stream, publishing new activities performed by the user, or listening to events that occurred to user's friends.

Following are the list of Opensocial APIs supported by this service

1. newFetchActivitiesRequest (more)
2. requestCreateActivity (more)

Following are the fields supported by the activity object

1. opensocial.Activity.Field.TITLE
2. opensocial.Activity.Field.POSTED_TIME
3. opensocial.Activity.Field.USER_ID (more)

 
           Example:
           
           <script type="text/javascript">

           function getActivities()
           {
            var req = opensocial.newDataRequest();
            req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS'), 'friends');
            req.add(req.newFetchActivitiesRequest('VIEWER'), 'viewerActivities');
            req.add(req.newFetchActivitiesRequest('VIEWER_FRIENDS'),'friendActivities');
            req.send(showActivities);
           }
    
           function showActivities(dataResponse)
           {
            var viewerActivities = dataResponse.get('viewerActivities').getData()['activities'];
            var friendActivities = dataResponse.get('friendActivities').getData()['activities'];
            var friends = dataResponse.get('friends').getData();
            var htmlout = '';
            htmlout += '<h2>Your activities:</h2><br>';
            htmlout += getActivitiesHtml(viewerActivities);
            htmlout += '<h2>Your friends\' activities:</h2><br>';
            htmlout += getFriendsActivitiesHtml(friendActivities,friends);
            document.getElementById('read_activities').innerHTML = htmlout;
           }

           function getActivitiesHtml(stream)
           {
            var htmlout = '';
            stream.each(function(activity)
            {
             htmlout += activity.getField('title');
             htmlout += '<br>';
            });
            return htmlout;
          }

          function getFriendsActivitiesHtml(stream,friends)
          {
           var htmlout = '';
           stream.each(function(activity)
           {
            var name="";
            var userId = activity.getField('userId');
            friends.each(function(person)
            {
             if(userId==person.getField('id'))
               name=person.getDisplayName();
            });
            htmlout += "<b>"+name+"</b>: "+activity.getField('title');
            htmlout += '<br>';
          });
          return htmlout;
        }
	
        function writeActivity()
        {
         var title = _gel('title').value;
         var params = {};
         params[opensocial.Activity.Field.TITLE] = title;
         var activity = opensocial.newActivity(params);
         opensocial.requestCreateActivity(activity,
         opensocial.CreateActivityPriority.HIGH, getActivities);
        }
        gadgets.util.registerOnLoadHandler(getActivities);

        </script>

       <div id="write_activities">
       Title:<input id="title" /><br>
       <input type="button" value="add activity" onclick="writeActivity();" />
       </div>
       <div id="read_activities">
       </div>
	
 

c. Persistence

To manipulate the user state or profile and to save and load additional information related to the user and that’s required by the application.

Following are the list of OpenSocial APIs supported by this service.

1. newFetchPersonAppDataRequest (more)
2. newUpdatePersonAppDataRequest (more)
3. newRemovePersonAppDataRequest (more)

 

             Example:

             <script type="text/javascript">

             var givenGifts = {};
             var globalGiftList = ['a cashew nut', 'a peanut', 'a hazelnut', 'a red pistachio nut'];

             function updateGiftList(viewer, data, friends)
             {
              var json = null;
              if (data[viewer.getId()])
              {
                json = data[viewer.getId()]['gifts'];
              }
              if (!json) 
              {
               givenGifts = {};
              }
              try
              {
               givenGifts = gadgets.json.parse(gadgets.util.unescapeString(json));
              }
              catch (e)
              {
                givenGifts = {};
              }
              var html = new Array();
              html.push('You have given:');
              html.push('<ul>');
              for (i in givenGifts)
              {
                if (i.hasOwnProperty)
                {
                 html.push('<li>', friends.getById(i).getDisplayName(), ' received ',
                 globalGiftList[givenGifts[i]], '</li>');
                }
               }
              html.push('</ul>');
              document.getElementById('given').innerHTML = html.join('');
             }

             function giveGift()
             {
              var nut = document.getElementById('nut').value;
              var friend = document.getElementById('person').value;
              givenGifts[friend] = nut;
              var json = gadgets.json.stringify(givenGifts);
              var req = opensocial.newDataRequest();
              req.add(req.newUpdatePersonAppDataRequest("VIEWER", 'gifts', json));
              req.add(req.newFetchPersonRequest("VIEWER"), 'viewer');
              var viewerFriends = opensocial.newIdSpec({ "userId" : "VIEWER", "groupId" : "FRIENDS" });
              var opt_params = {};
              opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 100;
              req.add(req.newFetchPeopleRequest(viewerFriends, opt_params), 'viewerFriends');
              var viewer = opensocial.newIdSpec({ "userId" : "VIEWER" });
              req.add(req.newFetchPersonAppDataRequest(viewer, 'gifts'), 'data');
              req.send(onLoadFriends);
             }

             function makeOptionsMenu()
             {
              var html = new Array();
              html.push('<select id="nut">');
              for (var i = 0; i < globalGiftList.length; i++)
              {
                html.push('<option value="', i, '">', globalGiftList[i], '</option>');
              }
              html.push('</select>');
              document.getElementById('gifts').innerHTML = html.join('');
             }
 
             function loadFriends()
             {
              var req = opensocial.newDataRequest();
              req.add(req.newFetchPersonRequest("VIEWER"), 'viewer');
              var viewerFriends = opensocial.newIdSpec({ "userId" : "VIEWER", "groupId" : "FRIENDS" });
              var opt_params = {};
              opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 100;
              req.add(req.newFetchPeopleRequest(viewerFriends,opt_params),'viewerFriends');
              var viewer = opensocial.newIdSpec({ "userId" : "VIEWER" });
              req.add(req.newFetchPersonAppDataRequest(viewer, 'gifts', opt_params), 'data');
              req.send(onLoadFriends);
             }

             function onLoadFriends(data)
             {
              var viewer = data.get('viewer').getData();
              var viewerFriends = data.get('viewerFriends').getData();
              var giftData = data.get('data').getData();
              html = new Array();
              html.push('<select id="person">');
              viewerFriends.each(function(person)
              {
               if (person.getId())
               {
                html.push('<option value="', person.getId(), '">', person.getDisplayName(), '</option>');
               }
              });
              html.push('</select>');
              document.getElementById('friends').innerHTML = html.join('');
              updateGiftList(viewer, giftData, viewerFriends);
             }
 
             function init()
             {
              loadFriends();
              makeOptionsMenu();
             }

             gadgets.util.registerOnLoadHandler(init);
             </script>

             <div id='main'>
             <div id='give'>
             <form id='gift_form'>
             Give <span id='gifts'></span> to <span id='friends'></span>. 
             <a href='javascript:void(0);' onclick='giveGift();'>Give!</a>
             </form>
             </div>
             <div id='given'></div>
             </div>

Note:

To support Friendster in our container, you have to create an application in Friendster with the following callback URL and provide the Friendster application's API key and secret key in the create application page in developer.vysr.com.

Callback URL:http://shindig.vysr.com/friendster/