Welcome Developers!

in

Welcome!

in

Simple API for Data Storage, OpenSocial 0.8

Last post 08-31-2009 12:19 PM by Claude. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 04-06-2009 11:11 AM

    Simple API for Data Storage, OpenSocial 0.8

    There seem to be plenty of examples for using the data store API to persist widget items, but  none of these examples seem to completely work. Can someone just post a simple---working---example of posting a piece of data, getting it back via a callback, and then using it in the callback function to display it on screen. Thanks. 

  • 04-17-2009 12:02 PM In reply to

    Re: Simple API for Data Storage, OpenSocial 0.8

    Hey, I'll check in and see if we have anything avail for this.
    Rhonda

  • 05-09-2009 3:58 AM In reply to

    Re: Simple API for Data Storage, OpenSocial 0.8

    i would like this too ^^ because i cant seem to get any data back, it always returns either [object object] or null, and i guess i am just doing something wrong

  • 05-14-2009 10:30 AM In reply to

    Re: Simple API for Data Storage, OpenSocial 0.8

    could someone please post an example of how to store a single string value, and then retrieve it and display it, that would probably clear it up a little for me, when i store a string, all i get back is an object.

  • 05-14-2009 11:10 AM In reply to

    Re: Simple API for Data Storage, OpenSocial 0.8

     I have sent toa request to the content team. When it's accepted and put on someone's agenda, I'll update.

    Rhonda

     

  • 05-16-2009 10:14 AM In reply to

    Re: Simple API for Data Storage, OpenSocial 0.8

    Nevermind, i have found a nice example on goolge code http://code.google.com/apis/opensocial/docs/0.8/devguide.html#Persistent , that shows how to store and retrieve the data, and i tested the code and it worked fully :)

  • 05-16-2009 10:29 AM In reply to

    Re: Simple API for Data Storage, OpenSocial 0.8

    there is an error somewhere in the code i will try and find it and upload the xml file to my server if i can fix it :)

  • 05-16-2009 10:33 AM In reply to

    Re: Simple API for Data Storage, OpenSocial 0.8

    nope no luck finding the error, anyone else want to try finding it, the xml document is uploaded at -removed link-

  • 08-31-2009 12:19 PM In reply to

    • Claude
    • Not Ranked
    • Joined on 04-02-2009
    • Posts 1

    Re: Simple API for Data Storage, OpenSocial 0.8

    Hi,

    I tried to execute the code at

    http://code.google.com/intl/de-DE/apis/opensocial/docs/0.8/devguide.html#Persistent

    but I am not able either to save and retrieve data on a viewer. If someone has an update about that please let me know.

    Here is the code that gives "undefined" as answer.

    Thanks in advance

        Claude

     

     <div id='loading'></div>
    <div id='heading'></div>
    <hr size='1px' />
    <div id='main'></div>

    <script type='text/javascript'>

    var os;
    var dataReqObj;
    var html = '';
    var heading = '';

    function putData()
    {
      dataReqObj = os.newDataRequest();
      var data1 = Math.random() * 5;
      dataReqObj.add(dataReqObj.newUpdatePersonAppDataRequest("VIEWER", "AppField1", data1));
      dataReqObj.add(dataReqObj.newUpdatePersonAppDataRequest("VIEWER", "AppField2", data1));
      dataReqObj.add(dataReqObj.newUpdatePersonAppDataRequest("VIEWER", "AppField3", data1));
      dataReqObj.send(handlePutData);
    }

    function handlePutData() {
         requestData();
    }

    function requestData()
    {
      var fields = ["AppField1","AppField2","AppField3"];
      var p = {};
      dataReqObj = os.newDataRequest();
      var req = dataReqObj;

      p[opensocial.IdSpec.Field.USER_ID] = "VIEWER";
      var idSpec = opensocial.newIdSpec(p);
      dataReqObj.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER), "viewer");
      dataReqObj.add(req.newFetchPersonAppDataRequest(idSpec, fields), "viewer_data");
      dataReqObj.send(handleRequestData);
    }

    function handleRequestData(data){
         if (data.hadError()) {
         alert(data.getErrorCode() + '\n' + data.getErrorMessage());
         return;
         }
         var viewer_data = data.get("viewer_data");
         var viewer = data.get("viewer");
         doSomethingWithMyData(viewer,viewer_data);
    }

    function doSomethingWithMyData(viewer,data) {
      var mydata = data.getData();
      var me = viewer.getData();

     var id = me.getId().substr(12, me.getId().length);
      html = "AppField1 data for user is: " +mydata[id]["AppField1"]+"<br />";
      document.getElementById('main').innerHTML = html;
    }

    function init() {
        os = opensocial.Container.get();
       putData();

    }

    init();
    </script>

Page 1 of 1 (9 items)