MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Retrieving Activities

Last post 10-22-2009 10:34 AM by El Jefe. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 11-20-2008 10:20 PM

    Retrieving Activities

    Application activity events from your friends will be shown on your Home Page and on your Friend Update page. Your Home Page will show a maximun of 50% of application events, and you will compete for this real estate with your fellow application developers. There is not much control you have in this area.

    You can also retrieve your events from your own application and show this on the application canvas page or on the profile page. Here is a little code sample that uses some jQuery to render the results:

    <span id="status"></span>

    <form>
     
    <fieldset>
       
    <label for="whom">Get application events for </label>
       
    <input type="radio" name="whom" value="viewer" checked="true"/>viewer<input type="radio" name="whom" value="owner" />or owner 
      
     <label for="justMyEvents">; show my events only</label>
       
    <input type="checkbox" name="justMyEvents" value="true" />
     
    </fieldset>
    </form>

     <div id="activiesFeed">.</div><div id="feedTxtToHtml">.</div>
    <
    script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
    <
    script>

    function getActivities(){
       $("#activiesFeed").html("");
       var showViewer = $("input[@name=whom]:checked").val() == 'viewer';
       var justMyEvents = $("input[@name=justMyEvents]:checked").val() == 'true';
      
    var idspec = opensocial.newIdSpec();

       if (showViewer) {
         idspec.setField(opensocial.IdSpec.Field.USER_ID, opensocial.IdSpec.PersonId.VIEWER);
       }
    else {
         idspec.setField(opensocial.IdSpec.Field.USER_ID, opensocial.IdSpec.PersonId.OWNER);
       }

       if (justMyEvents) {
           idspec.setField(opensocial.IdSpec.Field.NETWORK_DISTANCE, 0);
       }
    else {
           idspec.setField(opensocial.IdSpec.Field.NETWORK_DISTANCE, 1);
       }
      var dataRequest = opensocial.newDataRequest();
      dataRequest.add(dataRequest.newFetchActivitiesRequest(idspec,
    "activity"));
      dataRequest.send(processActivities);
    }

    function processActivities(response){
     
    try {
      
    var activitiesData = MyOpenSpace.RequestType.FETCH_ACTIVITIES;
       
    if (response.hadError() || response.get(activitiesData).hadError()) {
        
    if (response.get(activitiesData).getErrorCode() == opensocial.ResponseItem.Error.UNAUTHORIZED) {
               $(
    "#status").html("Unauthorized; requesting user for permission.");
               requestUserToReceiveActivities();
              
    return;
         }

         if (response.get(activitiesData).hadError()) {
            
    $("#status").html("Error getting activities");
            
    $("#status").append(response.get(activitiesData).getErrorCode());
            
    $("#status").append(response.get(activitiesData).getErrorMessage());
        
    }
        
    $("#status").append(response.getErrorMessage());
     
    } else {

    var receivedData = response.get(activitiesData).getData();
    $("#activiesFeed").append("<ol>");
     
    for (var item in receivedData.asArray()) {
      
    var timeTxt = receivedData.asArray()[item].getField("postedTime");
       
    // note: iconUrl is missing, but that would just be your regular icon for the app.
      
    var iconUrl = receivedData.asArray()[item].getField("streamFavIconUrl");
      
    var userId = receivedData.asArray()[item].getField("userId");
       
    var titleId = receivedData.asArray()[item].getField("titleId");
      
    var appId = receivedData.asArray()[item].getField("appId");
      
    var titleTxt = receivedData.asArray()[item].getField("title");
      
    var bodyTxt = receivedData.asArray()[item].getField("body");
      
    var oneUpdate = "";
       
    if (bodyTxt != null && bodyTxt.length > 0){
          
    oneUpdate = "<li> on " + timeTxt.substring(0,16) + ": <div>" + $("#feedTxtToHtml").html(titleTxt).text() + "<br/>" + $("#feedTxtToHtml").html(bodyTxt).text() + "</div></li>";
       
    } else {
          
    oneUpdate = "<li> on " + timeTxt.substring(0,16) + ": <div>" + $("#feedTxtToHtml").html(titleTxt).text() + "</div></li>";
       
    }

       $("#activiesFeed").append(oneUpdate);
     
    }

    $("#activiesFeed").append("</ol>");

    //make sure all hyperlinks get out of the iframe
    $("#activiesFeed a").attr("target", "_blank");
     
    //hide the helper dom object.
    $("#feedTxtToHtml").hide();
    }

    }

    catch (any){
     
    $("#status").html("<span style='color:red'>ERROR with rendering the feed.</span>");
     
    }

    }

    function requestUserToSentActivities(){
     
    opensocial.requestPermission([MyOpenSpace.Permission.VIEWER_SEND_UPDATES_TO_FRIENDS], "Let your friends know what you are doing.", checkPermissionResponseSent);
    }


    function requestUserToReceiveActivities(){
      opensocial.requestPermission([MyOpenSpace.Permission.VIEWER_SHOW_UPDATES_FROM_FRIENDS],
    "See what your friends are doing with this app!", checkPermissionResponseReceive);
    }


    function checkPermissionResponseSent(){
     
    //This does get called, but don't use alert statements. They are filtered by the container

    }


    function
    checkPermissionResponseReceive(){
     
    //This does get called, but don't use alert statements. They are filtered by the container
    }

    </script>

  • 02-03-2009 12:15 PM In reply to

    • sashi
    • Not Ranked
    • Joined on 07-17-2008
    • Posts 7

    Re: Retrieving Activities

     Hi Marco,

    I am facing the same issue that you have mentioned here for  opensocial.requestPermission. The callback function is not being called. Any idea when this feature will be implemented fully

     

    Regards

    Sashi

  • 02-27-2009 12:12 AM In reply to

    Re: Retrieving Activities

     I am also having problems with requestPermission not executing my callback.  Is that a known issue that's being fixed?

  • 05-05-2009 3:50 PM In reply to

    Re: Retrieving Activities

    Marco,

    Any updates on the issue that Sashi referenced above? It appears to be affecting multiple developers.

    Thanks!
  • 05-11-2009 9:48 AM In reply to

    Re: Retrieving Activities

    The call back functions are working fine.

    It turned out that the OpenSocial container 'eats' the alert statements. I will modify my code sample.

    In my demo app I changed the code to log the meggage to the Firebug console. 

    See the app here: http://www.myspace.com/427516622

     

  • 05-19-2009 12:57 AM In reply to

    • vishnu
    • Not Ranked
    • Joined on 09-16-2008
    • Posts 2

    Re: Retrieving Activities

    the app is not working..

  • 05-19-2009 2:00 AM In reply to

    • vishnu
    • Not Ranked
    • Joined on 09-16-2008
    • Posts 2

    Re: Retrieving Activities

     the code below is not working..

     

     

    <input type="button" value="click" onclick="sendActivity();">
    <div id="message"></div>
    <script
        src="http://x.myspacecdn.com/OpenSocial/references/gadgets003.js"
        mce_src="http://x.myspacecdn.com/OpenSocial/references/gadgets003.js"
        type="text/javascript"></script>
    <script
        src="http://x.myspacecdn.com/modules/common/static/js/Apps/ifpc003.js"
        mce_src="http://x.myspacecdn.com/modules/common/static/js/Apps/ifpc003.js"
        type="text/javascript"></script>
    <script
        src="http://x.myspacecdn.com/modules/common/static/js/Apps/json001.js"
        mce_src="http://x.myspacecdn.com/modules/common/static/js/Apps/json001.js"
        type="text/javascript"></script>
    <script
        src="http://x.myspacecdn.com/OpenSocial/IFPC_externalIframe004.js"
        mce_src="http://x.myspacecdn.com/OpenSocial/IFPC_externalIframe004.js"
        type="text/javascript"></script>

    <script type="text/javascript">
    function requestPermission(){
        var container = MyOpenSpace.MySpaceContainer.get();
        var permission = MyOpenSpace.Permission.VIEWER_SEND_UPDATES_TO_FRIENDS;
        var hasPerm = container.hasPermission(permission);
        if (hasPerm){
           document.getElementById("message").innerHTML = "You already have the permission.";
           return;
        }
        var callback = function (response){
           if (response.errorMessage){
              document.getElementById("message").innerHTML = "Error: " + response.errorMessage;
              if (response.permissions){
                 for (var i in response.permissions){
                    document.getElementById("message").innerHTML = "Permission Granted: " + response.permissionsIdea.permission;
                 }
              }
           }
           else if (response.permissions){
              for (var i in response.permissions){
                 document.getElementById("message").innerHTML = "Permission Granted: " + response.permissionsIdea.permission;
              }
           }
        }
        container.requestPermission(permission,"Test permission request", callback);
    }

    function sendActivity(){
        requestPermission();
        var params = {};
        params[MyOpenSpace.Activity.Field.TITLE_ID] = "Template_1";
        params[MyOpenSpace.Activity.Field.TEMPLATE_PARAMS] = {"book":"Harry potter"};
        params[MyOpenSpace.Activity.Field.MEDIA_ITEMS] = [;
       
        var container = MyOpenSpace.MySpaceContainer.get();
        var activity = container.newActivity(params);
       
        var opt_callBack = function(response){
           if (response.errorMessage){
              alert("Error:" + response.errorMessage);
              return;
           }
           switch (response){
              case MyOpenSpace.PostTo.Result.ERROR:
                 alert("Error");
                 break;
              case MyOpenSpace.PostTo.Result.CANCELLED:
                 alert("Cancelled");
                 break;
              case MyOpenSpace.PostTo.Result.SUCCESS:
                 alert("Success");
                 break;
           }
        }
        container.requestCreateActivity(activity, MyOpenSpace.CreateActivityPriority.HIGH, opt_callBack);
    }

    </script>
     

  • 06-07-2009 7:14 AM In reply to

    Re: Retrieving Activities

     Hi Vishnu,

    Are you still having a problem with this?

    Rhonda

     

  • 07-27-2009 1:20 PM In reply to

    • sashi
    • Not Ranked
    • Joined on 07-17-2008
    • Posts 7

    Re: Retrieving Activities

     Rhonda,

    Please confirm whether this is fixed for  opensocial.requestPermission also or for only activities.

    Regards

    Sashi

     

     

     

  • 10-22-2009 10:34 AM In reply to

    Re: Retrieving Activities

    Rhonda, Please confirm whether this is fixed for opensocial.requestPermission also or for only activities. Thanks!
Page 1 of 1 (10 items)