Personalize a gadget using appParams and appData

You can use a combination of appParams and appData to create a personalized gadget.

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Passing and storing paramaters on install" summary="" description="" author="" author_email="" thumbnail="" screenshot="" height="380">
<Require feature="opensocial-0.7"/>
<Require feature="views" />
</ModulePrefs>
 
	<Content type="html">
  	<![CDATA[
 
	<style>
	html, body {
		margin: 0; /* set the iframed page margin to zero */
		padding: 10px;
	}
	</style>
 
	<div id="content"></div>
 
    <script type="text/javascript">
 
 
	function init() {
		var req = opensocial.newDataRequest();
		req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER), "oOwner");
		req.add(req.newFetchPersonAppDataRequest("OWNER", "myKey"), "get_data");
		req.send(get_callback);
	}
 
	function get_callback(response) {
		var userid = response.get("oOwner").getData().getId();
		var data = response.get("get_data").getData();
		var myKey = data[userid]["myKey"];
 
		if (myKey != null) {
			var html = "<h3>appParams already stored</h3>";
			html += "<p>You've already succesfully stored the appParams on installation. Currently the params that are stored for this gadget is: <strong>" +myKey+ "</strong></p>";
			// Create HTML
			document.getElementById("content").innerHTML = html;
 
		} else {
			var appParams = gadgets.views.getParams();
			var installParam = appParams['data1'];
			var req = opensocial.newDataRequest();
			req.add(req.newUpdatePersonAppDataRequest("VIEWER", "myKey", installParam), "set_data");
			req.send(set_callback);
		}
	}
 
	// Check if the username has been set
	function set_callback(response) {
		if (response.get("set_data").hadError()) {
			alert("set callback failed: "+response.get("set_data").getErrorMessage());
		} else {
			var html = "<h3>Succesfully stored appParams!</h3>";
			html += "<p>You can now use them to personalize your gadget.</p>";
			// Create HTML
			document.getElementById("content").innerHTML = html;
		}
	}
 
	gadgets.util.registerOnLoadHandler(init);
 
	</script>
  	]]>
	</Content>
</Module>

Example install (Make sure you're not in OpenSocial Sandbox mode)

Example file