MySpace Developer Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Storing preference data for a given instance of an app?

Last post 07-08-2008 7:00 PM by $cott. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 04-09-2008 10:43 PM

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

    Storing preference data for a given instance of an app?

    Ok... I'm totally retarded, I think, and maybe I just need to experiment... but what is the proper way to store preference data for a given application?  Can I store it within myspace itself... or should I just save 'n' load it from my server?

  • 06-01-2008 8:25 PM In reply to

    Re: Storing preference data for a given instance of an app?

    I'm curious about this too as I've been stumped on this. I've read all the posts and cannot figure if the data api is still unavailable/taken down.  

     Can we use the data api to store data for applications or do we have to host our own DB. If we have to host our own database, does this typically involve writing a webservice to write data to the DB on my server. Any tips are greatly appreciated.

     Thanks, V

  • 06-01-2008 8:28 PM In reply to

    Re: Storing preference data for a given instance of an app?

     you're in the right place. Hopefully we can get you some answers soon

  • 06-01-2008 8:47 PM In reply to

    Re: Storing preference data for a given instance of an app?

    http://developer.myspace.com/community/myspace/faq.aspx#storedata

    Does this help ? 

  • 06-02-2008 8:46 PM In reply to

    Re: Storing preference data for a given instance of an app?

    Hi, thanks for your response. It does help.

    I still needed to know if the DATA API is available for our use to store our app data values. When I try to use it I get no results and no errors so I cant really tell if its working.... Not sure if its not fully functional.

    Am trying to use the newFetchPersonAppDataRequest & newUpdatePersonAppDataRequest to retrieve data and update data for a user.  Ibelieve the newUpdatePersonAppDataRequest function is working but cannot validate this as the newFetchPersonAppDataRequest is not working. I do not get any errors nor do I get any results. Provided below is the code I am using. The callback for getdata does not get fired at all. And inside getdata how do I retrieve our keydata?

    Thanks again,

    V

     

    function GetData()

    {

                    os = opensocial.Container.get();   

                    req = os.newDataRequest();  

                    req.add(os.newFetchPersonAppDataRequest("VIEWER", "mykeyname"));

                    req.send(getVariable_callback);

                    alert("here");

                   

    }

     

    function getVariable_callback(data)

    {

                    if (response.hadError())

                    {

                                    alert("error occurred");

                    }

                    else

                    {

                                    alert("no error");

                    }

                   

    }

     

    function SetData()

    {

                    var req = opensocial.newDataRequest();

                    req.add(req.newUpdatePersonAppDataRequest("VIEWER", "mykeyname", "mykeyvalue"));

                    req.send(setVariable_callback);

    }

     

    function setVariable_callback(response)

    {

                    alert("inside callback");

    }

     

    </script>

  • 06-18-2008 4:35 PM In reply to

    Re: Storing preference data for a given instance of an app?

    I would also appreciate a response to this.

  • 06-19-2008 8:34 AM In reply to

    Re: Storing preference data for a given instance of an app?

     I am also getting the same symptom.  In firebug if you look at the PUT query, the response is

    <h1>Length Required</h1>
     
    ???
     
    Is this happeneing to anyone else? 

     

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

    Re: Storing preference data for a given instance of an app?

    Hi Vidette, it looks like you have a small bug in your code, the argument for getVariable_callback is named "data", but then you access it with "response".  I copied and pasted your code into an app, changed "data" to "response" and everything worked fine.

    As for the Length Required error, I've seen that before when a makeRequest is specified as a POST but no post parameters are given, is that the issue you're seeing?

  • 06-24-2008 3:13 PM In reply to

    Re: Storing preference data for a given instance of an app?

    I'm receiving this "Length Required"  "error" also when trying to update a user's AppData. I've gone through the docs and don't see anything wrong, so I'm kind of assuming it's a bug somewhere. The one convenient thing is that the data I'm sending is actually updated. Unfortunately, that means I'm doing some weird chaining of functions together and having to make an additional call to load the newly saved data.

    For example, this code works:

    function setupForm(data){
        //do something with the AppData
    }
    function checkLogin(){

        data = { "user": document.getElementById('user').value, "somevalue": document.getElementById('somevalue').value };
        req = os.newDataRequest();
        req.add( req.newUpdatePersonAppDataRequest('VIEWER', MY_CFG_KEY, gadgets.json.stringify(data)) , 'myval');
        req.send(cb_checkLogin);
    }

    function cb_checkLogin(resp){
        var req = os.newDataRequest();
        req.add( req.newFetchPersonAppDataRequest('VIEWER', MY_CFG_KEY), 'myval');
        req.send(setupForm);
    }

     

    However, from the docs it looks like should be able to call "setupForm" as the callback in "checkLogin" instead of having to send it through "cb_checkLogin" to load the data back and then send it to "setupForm".

    Any one have an idea of what's causing that or how to fix it/do it correctly?

     

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

    Re: Storing preference data for a given instance of an app?

     Could I get an example of a function that would handle the returned data object when requesting a piece of data that was stored in a key earlier? I can't seem to figure it out. Thanks! :)

     


  • 06-30-2008 2:05 PM In reply to

    Re: Storing preference data for a given instance of an app?

    Is this actually working now?  I just read that it's not implemented yet: http://developer.myspace.com/community/myspace/opensocial.aspx.  Look at the bottom of the page where it says 'Stuff that isn't Implemented'.  It lists the Data and Activities API as not working yet.  I also tried with a gadget that works perfectly on orkut but fails saving the data on MySpace.  I spent the entire weekend struggling over this so if somone knows that it does work I would be very interested in having a discussion.  Having persistent user and application storage would greatly simplify my current application which depends on an external server to save name value pairs in a SQL database.

  • 06-30-2008 6:43 PM In reply to

    Re: Storing preference data for a given instance of an app?

     FINALLY! I got it to work. Copy and paste the code below (an example provided by Google's OpenSocial developer guide). I tried this example before but could not get it to work. It's pretty dense, so I'm going to be studying it for a while

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

    <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, "update_appdata");
    }

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

    /************************************************************************
    * Fetch app data
    */
    function requestMyData() {
    var req = opensocial.newDataRequest();
    var fields = [ "AppField1", "AppField2", "AppField3" ];
    req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), "viewer");
    req.add(req.newFetchPersonAppDataRequest("VIEWER", 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.getError();
    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>

     

  • 06-30-2008 7:03 PM In reply to

    Re: Storing preference data for a given instance of an app?

    Yeah, I was able to get that to work as well.  What I want to do is to store json for objects and rehydrate them later.  I suppose I could store everything as separate pieces of data but it would be so much easier to be able to store the json.  Maybe my code had a bug.  I read that they weren't supporting it yet so I gave up and bought hosting so I can store data on another server.

  • 06-30-2008 7:06 PM In reply to

    Re: Storing preference data for a given instance of an app?

    Ah yea, I see what you mean, looks like for now it only is supporting basic data types. Oh well, that's all I need for the time being.
  • 07-01-2008 11:19 PM In reply to

    Re: Storing preference data for a given instance of an app?

    Hmmm, even that code is no longer working.  I can see the Settings values change as they are randomly generated upon each page load, but I am not seeing the values read changing.  Also, the very first time I ran it I was only able to read the first value, the last two were undefined.  Now the values can be read but they don't change.  That coupled with the fact that you can't store JSON, which is just a string anyway, I'm still thinking this is broken.

    I'm hoping someone from MySpace can chime in on this as to whether this is supported or if something may be broken.

Page 1 of 2 (18 items) 1 2 Next >