Setting and fetching appdata

Storing of viewer data (you can store up to 10kb with each instance).

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="appData example" summary="" description="" author="" author_email="" thumbnail="" screenshot="" height="380">
	<Require feature="opensocial-0.7"/>
</ModulePrefs>
<Content type="html">
	<![CDATA[
	<script type="text/javascript">
 
	function get_callback(response) {
		// response.get("oViewer").getData().getId();
		var userid = response.get("oViewer").getData().getId();
 
		if (response.get("get_data").hadError()) {
		        alert("get callback failed");
		} else {
		        var data = response.get("get_data").getData();
		        alert(data[userid]["myKey"]);
		        alert("get callback suceeded");
		}
	};
 
	function set_callback(response) {
		if (response.get("set_data").hadError()) {
		        alert("set callback failed: "+response.get("set_data").getErrorMessage());
		} else {
			alert("set callback succeeded");
		}
	};
 
	function get_request() {
		var req = opensocial.newDataRequest();
		req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), "oViewer");
		req.add(req.newFetchPersonAppDataRequest("VIEWER", "myKey"), "get_data");
		req.send(get_callback);
	};
 
	// set data with the current time as value and with key "myKey"
	function request() {
		var req = opensocial.newDataRequest();
		var sTime = getCurrentTime().toString();
		req.add(req.newUpdatePersonAppDataRequest("VIEWER", "myKey", sTime), "set_data");
		req.send(set_callback);
	};
 
	function getCurrentTime() {
		var currentTime = new Date()
		return currentTime;
	}
	</script>
	<br>
	&nbsp;<input type="button" value="Set appdata" onClick="request();">&nbsp;
	<input type="button" value="Get appdata" onClick="get_request();">
	]]>
</Content>
</Module>

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

Example file