Hi Arne,

I have confirmed the updated document. But, unfortunately, there are
some mistakes yet. I send a complete code here, and replace it,
please. :)

---
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="Data Persistence Example">
    <Require feature="opensocial-0.8"/>
  </ModulePrefs>
  <Content type="html">
  <![CDATA[

  <script type="text/javascript">
   gadgets.util.registerOnLoadHandler(populateMyAppData);
   var htmlout = "";
   var me = null;

   /**
    * Set user data
    */
   function populateMyAppData() {
     var req = opensocial.newDataRequest();
     var data1 = Math.random() * 5;
     var data2 = Math.random() * 100;
     var data3 = new Date().getTime();
     htmlout += "Setting AppField1 to " + data1 + "<br />";
     req.add(req.newUpdatePersonAppDataRequest("VIEWER", "AppField1",
data1)) + "<br />";
     htmlout += "Setting AppField2 to " + data2 + "<br />";
     req.add(req.newUpdatePersonAppDataRequest("VIEWER", "AppField2",
data2)) + "<br />";
     htmlout += "Setting AppField3 to " + data3 + "<br />";
     req.add(req.newUpdatePersonAppDataRequest("VIEWER", "AppField3",
data3)) + "<br />";
     req.send(handlePopulateMyAppData);
   }

   /**
    * Handle responses from update person app data requests
    */
   function handlePopulateMyAppData(data) {
     if (data.hadError()) {
       htmlout += data.getErrorMessage();
     }
     requestMyData();
   }

   /**
    * Fetch app data
    */
   function requestMyData() {
     var req = opensocial.newDataRequest();
     var fields = [ "AppField1", "AppField2", "AppField3" ];
     var p = {};
     p[opensocial.IdSpec.Field.USER_ID] = "VIEWER";
     var idSpec = opensocial.newIdSpec(p);
 
req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER),
"viewer");
     req.add(req.newFetchPersonAppDataRequest(idSpec, fields),
"viewer_data");
     req.send(handleRequestMyData);
   }

   /**
    * Handle responses from app data requests
    */
   function handleRequestMyData(data) {
     var mydata = data.get("viewer_data");
     var viewer = data.get("viewer");
     me = viewer.getData();

     if (mydata.hadError()) {
       htmlout += data.getErrorMessage();
       return;
     }
     // Do something with the returned data - note the getData call
     doSomethingWithMyData(mydata.getData());
   }

   /**
   * Operate on user data
   */
   function doSomethingWithMyData(data) {
     //Data is indexed by user id, and represents an object where
keys
     //correspond with the app data fields.
     var mydata = data[me.getId()];
     var div = document.getElementById('content_div');
     htmlout += "My AppField1 data is: " + mydata["AppField1"] + "<br /
>";
     htmlout += "My AppField2 data is: " + mydata["AppField2"] + "<br /
>";
     htmlout += "My AppField3 data is: " + mydata["AppField3"] + "<br /
>";
     div.innerHTML = htmlout;
   }

 </script>
 <div id="content_div"></div>
  ]]>
  </Content>
</Module>
---

Best regards,
Yoichiro


On 9月24ζ—₯, 午後3:15, [EMAIL PROTECTED] wrote:
> Whoops, sorry about the errors!  Guess this bit just got left in from
> the old document.  We'll update the document tomorrow.
>
> Thanks for reporting these!
> ~Arne
>
> On Sep 23, 10:59 pm, yoichiro <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > Eiji and I found some mistakes at the sample code of the persistence
> > api in Developer's guide for v0.8.
>
> >http://code.google.com/apis/opensocial/docs/0.8/devguide.html
>
> > The point is the following:
>
> > Line 28:
> > req.send(handlePopulateMyAppData, "update_appdata");
> > Correct code is:
> > req.send(handlePopulateMyAppData);
>
> > Line 36:
> > htmlout += data.getError();
> > Correct code is:
> > htmlout += data.getErrorMessage();
>
> > Line 47:
> > req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER),
> > "viewer");
> > Correct code is:
> > req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER),
> > "viewer");
>
> > Line 48:
> > req.add(req.newFetchPersonAppDataRequest("VIEWER", fields),
> > "viewer_data");
> > Correct code is:
> > var p = {};
> > p[opensocial.IdSpec.Field.USER_ID] =
> > opensocial.IdSpec.PersonId.VIEWER;
> > var idSpec = opensocial.newIdSpec(p);
> > req.add(req.newFetchPersonAppDataRequest(idSpec, fields),
> > "viewer_data");
>
> > Line 61:
> > htmlout += data.getError();
> > Correct code is:
> > htmlout += data.getErrorMessage();
>
> > We confirmed to execute the code successfully with hi5 by correcting
> > these. Can anyone correct the sample code in developer's guide?
>
> > Regards,
> > Yoichiro
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OpenSocial Application Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/opensocial-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to