MySpace Developer Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

(Example Code) Global App Data

Last post 05-31-2008 9:29 PM by Critter. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 04-04-2008 6:24 AM

    (Example Code) Global App Data

    This come up recently, and it's now implemented. It works a bit differently than Person App Data, so I thought I'd post some code:

    <!-- Some HTML for UI and output --> 
    <form name="data_test">
    Key:<input name="key" value="key"/></br>
    Value:<input name="value"  value="value"/></br>
    <input type="button" onclick="updateData();" value="Update Data" /></br>
    </form>
    <hr />
    <div id="output"></div>
    <input type="button" onclick="readData();" value="Read Data" />

    <!-- Script section for reading and updating data -->
    <script type="text/javascript" id="global_data_test">
    function updateData() {
      var os = opensocial.Container.get();
      var dr = os.newDataRequest();
      var key = document.data_test.key.value;
      var value = document.data_test.value.value;
      dr.add(os.newUpdatePersonAppDataRequest(MyOpenSpace.Group.GLOBAL_APP_DATA, key, value), 'appvar');
      dr.send(updateSent);
    }

    function updateSent(response) {
      if(response.hadError()) {
        document.getElementById('output').innerHTML = "Error updating data.";
      } else {
        // Because of the async way data is updated, you should probably
        // refresh before attempting to read.
        document.getElementById('output').innerHTML = "Global data updated!<br><i>Wait a moment or refresh before reading.</i>";
      }
    }

    function readData() {
      var os = opensocial.Container.get();
      var dr = os.newDataRequest();
      // I don't know the name(s) of the keys, so collect them all
      dr.add(os.newFetchPersonAppDataRequest(MyOpenSpace.Group.GLOBAL_APP_DATA, '*'), 'appvar');
      dr.send(fetchSent);
    }

    function fetchSent(response) {
      var data = response.get('appvar').getData();
      var html = '';
      // Go through each key-value pair. Note the difference from a Person App Data call
      // using a PersonId -- the data collection isn't keyed to an Id or other value.
      for(var key in data) {
        html += key + " : " + data[key] + "<br/>";
      }
      document.getElementById('output').innerHTML = html;
    }

    </script>

    And, in case anyone is wondering - Global data is global - it's the same across all App installations.

  • 04-04-2008 2:24 PM In reply to

    • mNeo
    • Top 25 Contributor
    • Joined on 02-05-2008
    • Posts 107

    Re: (Example Code) Global App Data

    Thanks Jeremy. Is it allowed to save the user name or user thumbnail URL in the global data? For example, can we save the key - value combination of userid - userthumbnailURL? The ToS says that we can not export any user specific info. But since the global data resides in MySpace, we won't really be exporting anything. So, is it allowed?

    Also, what kind of limitations do we have on the apps data? As in, how many key-value pairs can we save or how many KBs of data can we save etc. 

  • 04-04-2008 3:06 PM In reply to

    Re: (Example Code) Global App Data

    As far as limitations: 1KB would be my guess - it's technically a keyed value like any other AppPersonData, so that limit would still hold. At least, I think.

    No idea about the thumbnail URL -- I've been thinking about it since yesterday and arguing myself in circles, but because there is no mechanism to remove a user's picture if they uninstall your App, I'm gonna side with caution and say it's probably still not allowed. When they uninstall, they take away their permission to use their data, but you're never informed of it from the perspective of OpenSocial, so you could technically persist it until the URL is no longer valid (if they, say, cancel their account). In fact, it could hold on to it beyond that, since there's no way within OpenSocial to even confirm that the URL still points to a valid picture.

  • 04-04-2008 5:01 PM In reply to

    • mNeo
    • Top 25 Contributor
    • Joined on 02-05-2008
    • Posts 107

    Re: (Example Code) Global App Data

     Yeah .. I agree with both of your points. Chances are that the global data limit will also be 1KB. And because there's no way for us to remove a user's info when he/she uninstalls the app, perhaps we won't be allowed to store the info in the global storage. Moreover, if the global data limit is 1KB, then we can't save that much info anyway Sad

  • 04-10-2008 3:55 PM In reply to

    Re: (Example Code) Global App Data

     

    Jeremy, your example of Global App Data is currently not working. I tested under IE and FF.

    There were some strange changes in the MDP today. I had to change the code for my Weather app, because it no longer returns a null object for newFetchPersonRequest('VIEWER') when the viewer is not a registered user. This is different than it has been for the past week. Let me know if you noticed any other changes in the MDP today.

    I can really use a working example of Global App Data, because this feature will allow for much additional functionality.

     

  • 04-10-2008 5:00 PM In reply to

    • mNeo
    • Top 25 Contributor
    • Joined on 02-05-2008
    • Posts 107

    Re: (Example Code) Global App Data

    AppAuthor:

    I had to change the code for my Weather app, because it no longer returns a null object for newFetchPersonRequest('VIEWER') when the viewer is not a registered user.

     

    So what does it return now?

  • 04-10-2008 5:37 PM In reply to

    Re: (Example Code) Global App Data

    mNeo, to answer your question:

    newFetchPersonRequest('VIEWER') now returns a non-null object, even though the viewer is not an installed user. This didn't happen this morning.

    To determine that the returned object is for an installed user, I now have to test the object that is returned by the 'get' method:

    var objTemp = objData.get('viewerdata');
    if (objTemp !=null) {

    Play with the Weather app, and this will make more sense. The app only "permanently" remembers the Zip Code for the owner.

    ------------------------------------------------------------

    mNeo: Could you please confirm that Jeremy's example also fails when you try to use it? When I click [Update Data] on his app, it displays "Error updating data."

  • 04-10-2008 8:08 PM In reply to

    • Roig
    • Not Ranked
    • Joined on 04-08-2008
    • Posts 2

    Re: (Example Code) Global App Data

     Hey... just so I understand, weather app dude, you're handling the saving of the zipcode like this?

     

     var objUpdatePersonAppDataReq = objOpensocial.newUpdatePersonAppDataRequest('VIEWER', 'zipcode', gsZipCode);
     
     ... and loading it like this:
     
    var objFetchPersonAppDataReq = objOpensocial.newFetchPersonAppDataRequest('OWNER', 'zipcode'); 
     
    Thanks for the example! Helps a lot!
     
     

     

  • 04-12-2008 7:40 AM In reply to

    Re: (Example Code) Global App Data

    Just to add a note here in case this get's stumbled upon later:

    As noted above, this example code no longer works -- that's because Global App Data has been removed for security reasons. OpenSocial AppData now conforms only to OS 0.7 specifications.

     http://developer.myspace.com/Community/forums/t/1711.aspx

  • 05-31-2008 9:29 PM In reply to

    Re: (Example Code) Global App Data

     what would be another way of persisting data, then?

Page 1 of 1 (10 items)