5 Replies Latest reply on Jun 19, 2013 12:35 PM by dfilip

    Using JS API to Read/Write Personalization Data

    dfilip

      I am looking for pointers on how to read and write personalization data from a Jive app using the JavaScript API.  Either the Jive Core or Open Social APIs, which I have looked at but both of which are kinda big, and am looking for some pointers as to which functions I need to use to allow an app to write user-specific data, and how to read that data back, using JS (or REST, which I can use with jQuery, if that is the only way to do it).  Ideally, if anyone has any pointers to a working example, that would be even better!

       

      Apologies in advance if this should be obvious, and I have tried to RTFM, but think I am getting lost in the weeds, which is why I am looking for some advice.

       

      Thanks!

       

      Dave.

        • Re: Using JS API to Read/Write Personalization Data
          dfilip

          BTW - I should mention that this is for writing Jive 6 apps, and as I understand it, createExtProps/getExtProps functions are not supported prior to 7:

           

          document.createExtProps -> not a function?

           

          So again, looking for pointers on how to do this, but on Jive 6.

            • Re: Using JS API to Read/Write Personalization Data
              dfilip

              Can anyone tell me how a Jive 6 app can store user personalization data using either the Jive Core or Open Social APIs?

               

              Craig McClanahan can you provide any pointers?

               

              I am assuming that it is possible, but if it is not -- at least until Jive 7 with createExtProps/getExtProps -- then please let me know!

               

              I would like to avoid having to save personalization data for a Jive app on an external cloud server ... that just "feels wrong".

               

              Basically, just want to have a Jive app -- through either JS or the REST API -- be able to save/retrieve a string of data for the current app for the current user.  Thanks!

                • Re: Using JS API to Read/Write Personalization Data

                  The OpenSocial "appdata" APIs would be worth checking out, although the data written by one user of the app can be read (but not modified) by other users.

                   

                  Another alternative would be the OpenSocial "preferences" API.  This stays private to a user, and has nice UI support in Jive -- you can either declare the set of fields in your app.xml file and Jive will build an input screen for them, or you can provide a view for a completely customized user experience to set the preferences.  (Or, you can just get and set them programatically.)

                  1 person found this helpful
                    • Re: Using JS API to Read/Write Personalization Data
                      dfilip

                      Thanks Craig!  I think I want to use the OpenSocial Prefs API ...and I have seen the example code to define values in the XML of a Jive app, and a default 'form' that gets generated so that the user can enter their preferences:

                       

                      Jive Apps Developer Community: Using the OpenSocial API

                       

                      However, I'm trying to understand how to do that all programatically.  Is the gist that I can use the OpenSocial gadgets.Prefs to do this:

                       

                      Gadgets.Prefs (v0.9) - OpenSocial Documentation - OpenSocial Wiki

                       

                      and use the .set(name, obj) and .getString(name) methods from that to define and retrieve user preferences?  Do I need to define the preferences in the XML, as shown in the first example, or will the API allow me to set/get{Type} any arbitrary parameters that I want?  Ideally, I would like to be able to set/get preferences that the user never sees, and are set solely by the app, but I guess my overall question is around what I need to include in the XML vs. what preferences I can control solely through the API.  The app that I'm writing will need to save search results that will look like gobbledegook to the user.

                       

                      I am assuming that once I include:

                       

                      <Require feature="opensocial-1.0"/>

                      <Require feature="osapi"/>


                      in my app, I will have access to the entire OSAPI, including -- in this particular case -- a 'gadget' object?


                      Thanks,


                      Dave.

                • Re: Using JS API to Read/Write Personalization Data
                  dfilip

                  OK, I got some "sandbox time" today to play, and was able to figure this out.  Here is a simple example of using the OpenSocial Preferences (gadgets.Prefs) API to set and read an arbritrary user preference variable (which does NOT need to be exposed to the user in 'Your Settings' if you don't want it to be), in case anyone else is looking for this (I was and couldn't find it).  Sample app.xml below.  Cheers to Craig McClanahan for pointing me in the right direction!

                   

                  <?xml version="1.0" encoding="UTF-8" ?>

                  <Module>

                      <ModulePrefs title="OpenSocial Prefs Test">

                      <Require feature="opensocial-1.0"/>

                      <Require feature="osapi"/>

                      <Require feature="setprefs"/>

                  </ModulePrefs>

                  <Content type="html" view="home,canvas">

                    <![CDATA[

                   

                        <script  type="text/javascript">

                    function init() {

                    var prefs = new gadgets.Prefs();

                    document.getElementById('citySpan').innerHTML = prefs.getString("city");

                    }

                    function saveCity() {

                          var prefs = new gadgets.Prefs();

                    var myCity = document.getElementById('newCity').value;

                    prefs.set("city", myCity);

                    alert("My City has been set to: " + myCity);

                    }

                    function getCity() {

                          var prefs = new gadgets.Prefs();

                          var myCity = prefs.getString("city");

                    alert("My City = " + myCity);

                    document.getElementById('citySpan').innerHTML = myCity;

                    }

                    gadgets.util.registerOnLoadHandler(init);

                        </script>

                   

                        <p>My City: <span id='citySpan'></span></p>

                        <hr/>

                        <p>

                    New City: <input type="text" id="newCity" size="50">

                     

                    <input type="button" value="Save" onClick="JavaScript:saveCity();">

                     

                    <input type="button" value="Get" onClick="JavaScript:getCity();">

                        </p>

                        <hr/>

                   

                        ]]>

                  </Content>

                  </Module>