MySpace Developer Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Unable to update VIEWER data

Last post 06-25-2008 12:48 PM by Pete. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-24-2008 11:05 PM

    • Pete
    • Not Ranked
    • Joined on 06-23-2008
    • Posts 3

    Unable to update VIEWER data

    I have been working on a script that would allow a user insert a key code into a field for later retrieval.  The first part of the script checks to see if the OWNER and the VIEWER are  the same  using the ID field.  If they are then it checks to see if there is any data in a particular key that I have defined called "IDENT".   If the value comes back as "undefined",  the user is prompted with a form  that asks for a pass code. When this form is submitted it goes to a function that uses 'UpdatePersonAppDataRequest()' to update the key "IDENT".   It then goes to a callback function that alerts if there is an error or not.  If there is no error it goes back to check to see if the key "IDENT" has been updated.

    Here is the issue. When I call 'UpdatePersonAppDataRequest()'  and attempt to update the "IDENT" field it comes back with no errors, but when I try to check to see if this field now contains a value it still comes back as 'undefined'. I have checked to see if the value is being passed from the form and it is.  Am I missing something here?  Below is the code I have been working on.  I would appreciate any input  anyone might have.  Thanks in advance

     var os;
    var dataReqObj;


    function init() {

        os = opensocial.Container.get();
        dataReqObj = os.newDataRequest();
        var viewerReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER);
        var ownerReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER);
        
        dataReqObj.add(viewerReq);
        dataReqObj.add(ownerReq);

        dataReqObj.send(viewerResponse);

    }

    function viewerResponse(data) {

        var viewer = data.get(opensocial.DataRequest.PersonId.VIEWER).getData();
        var viewer_id = viewer.getId();
        
        var owner = data.get(opensocial.DataRequest.PersonId.OWNER).getData();
        var owner_id = owner.getId();
        
    //check to see if they have posted data yet if not we will prompt them to enter their pass key
        if(owner_id == viewer_id)   {
           
    //if the external id is undefined we need to prompt the user for a value
          var ext =  viewer.getField(opensocial.Person.Field.IDENT);
        
               if(ext == undefined) {
              alert(ext);
                 prompt_form();              
                }else{
              alert('fubar');
                }
        
          //end if owner     
          }
       // end function viewer response
    }



    function prompt_form()   {
    var sty = ".style";
    var formFrame = eval('document.getElementById("linkbox")' + sty);
    formFrame.visibility = "visible";
    }


    function keyCode() {
    var  keyfield = document.form1.keycode.value;
    var req = opensocial.newDataRequest();
    req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,"IDENT","keyfield"),"set_data");
    req.send(set_callback);

    }

    function set_callback(response) {
      if (response.get("set_data").hadError()) {
       alert('there was an error')
      } else {
        init();
      }
    }





    init();

     

  • 06-25-2008 10:18 AM In reply to

    Re: Unable to update VIEWER data

     Is this happening on the profile canvas when the viewer does not have the app installed?

    I am having an issue that might be related 

  • 06-25-2008 12:23 PM In reply to

    • kanya
    • Top 500 Contributor
    • Joined on 06-17-2008
    • Posts 6

    Re: Unable to update VIEWER data

    I am not sure as how you are trying to fetch the key and value. Try using newFetchPersonAppDataRequest. your code seems to be setting the correct value to the key IDENT
  • 06-25-2008 12:48 PM In reply to

    • Pete
    • Not Ranked
    • Joined on 06-23-2008
    • Posts 3

    Re: Unable to update VIEWER data

     Thanks. I just realized that I have been looking in the wrong classes for the "key" value. When using 'newUpdatePersonAppDataRequest', if you wish to extract the value you have to use 'newFetchPersonRequest' and 'newFetchPersonAppDataRequest'.  I also realized that these values come back as a name/value pair.  Below is the corrected code. It is working now.

     var req1 = opensocial.newDataRequest();
    req1.add(req1.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), 'viewer');
    req1.add(req1.newFetchPersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER, "IDENT2"), "key_data");
    req1.send(set_callback1);

    function set_callback1(resp) {
      if (!resp.hadError()) {
        var data = resp.get('key_data').getData();
        var viewer = resp.get('viewer').getData();
        var viewerData = data[viewer.getId()];
        var result = viewerData['IDENT2'];
         
         alert(result);
         
         
      }
    }

     

     

Page 1 of 1 (4 items)