Welcome Developers!

in

Welcome!

in

Apps seems don't store data

Last post 05-16-2009 4:20 AM by mike. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-13-2009 11:38 AM

    • mike
    • Top 75 Contributor
    • Joined on 02-08-2009
    • Posts 62

    Apps seems don't store data

    Hi to all,

    I've a big problem saving persistent data from javascript,
    I have tested application but seem save but when I read
    fields is always void

    here's the function that I have already testing on my local shindig and work fine

    1) if I use opensocial.IdSpec.PersonId.OWNER to write  an error message: invalid IdSpec, only viewer seems to work
        in my case Viewer and Owner it's the same people


    2) I wonder if it's possible, if viewer is different peolple form owner, read data from Owner

    3) Although Viewer seems work still no save data so "theData" is always undefined

     

    Here's the sources

    /**

    check if a field exist the call start function

    */ 

     

     function testAppData()
        {  
         prnLn("checking memory ...","out1");   
         var req = opensocial.newDataRequest();   
        
         var p = new Array();          
         p[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;   //es. OWNER       
         var idSpec = opensocial.newIdSpec(p);
        
        
         req.add(req.newFetchPersonAppDataRequest(idSpec, "MdC"), "key_data");   
         req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER), "peopleID");
         req.send(handleTestAppData);     
         
        }

    function handleTestAppData(data){
          
         var error=null;
         var isAlreadyInit=false;
        
         if (data.get("key_data").hadError()) {
               error = data.get("key_data").getErrorMessage();
               prnLn("Error (handleTestAppData): "+error);
                                                                           return;
         }

         if (data.get("peopleID").hadError()) {
               error = data.get("peopleID").getErrorMessage();
               prnLn("Error (handleTestAppData): "+error);
                                                                           return;
         }

        
         var peopleData = data.get("peopleID");
         var dest = peopleData.getData();
        
         var data = data.get("key_data").getData();     
         var theData = data[dest.getId()];

    prnLn("ID :"+dest.getId()+"data: "+theData,"out1"); 
       
         for (i in theData)
         { 
    prnLn(":" + i + ":","out1");     
          isAlreadyInit=true;
         }
        
         if(!isAlreadyInit){
        
          prnLn("please wait, initializing memory...","out1"); 
           var req = opensocial.newDataRequest();    
    var JsValue = gadgets.json.stringify({"string" : "some data"});


                                                        
    req.add(req.newUpdatePersonAppDataRequest( opensocial.IdSpec.PersonId.VIEWER, "MdC", JsValue),"set_data");  

           req.send(handleStoreAppId);
    prnLn("please wait, initializing memory2...","out1");
            
            
         }else{
           prnLn("memory ok...","out1");
           //clearMsg("out1");
           
           start();
         }
         
             
        
        }

  • 05-13-2009 5:54 PM In reply to

    Re: Apps seems don't store data

    Hi, thanks for the feedback, I'll escalate to container team for additional info.

    Rhonda

     

  • 05-14-2009 5:36 PM In reply to

    Re: Apps seems don't store data

    Hi, there are a few things issues with the code you pasted.

    1. It doesn't make a difference in this case, but for the future this:

    var p = new Array();

    Inside testAppData should be "var p = new Object();", or "var p = {};", as those optional parameters should be associative arrays and not linear arrays like var p = new Array() or var p = [.

    2. It looks like you're fetching the person data just for the user's ID to use it to access the app data response.  You don't need to make an API call to get this, we push it down for you.  To get the owner and viewer IDs, do this:

    gadgets.views.getParams().ownerId

    gadgets.views.getParams().viewerId

    3. This will be rendered moot if you implement #2 above, but IDs are returned in 0.8 in this format: myspace.com:6221.  But the app data is keyed on just the integer part of the ID (e.g. 6221).  So when you do this: var theData = data[dest.getId()]; the getId() returns myspace.com:<user ID>, which doesn't exist inside of the data object.  So you can either strip the "myspace.com:" out of the returned ID, or use the method above to get the IDs.

    Thanks,

    Chad

  • 05-16-2009 4:20 AM In reply to

    • mike
    • Top 75 Contributor
    • Joined on 02-08-2009
    • Posts 62

    Re: Apps seems don't store data

    Wow you are really a guru, Thanks I try it and now works really well! really persistent... but id get directly from gadget is compatible, or just is for myspace.com, thanks :)
Page 1 of 1 (4 items)