help !!! add multiple values in a key, how?

0 views
Skip to first unread message

Vinicius

unread,
Jun 30, 2008, 12:25:43 PM6/30/08
to Orkut Developer Forum
<script type="text/javascript">
gadgets.util.registerOnLoadHandler(requestComm);

var htmlout = "";
var me = null;
var aff = [];

function AddComm() {
var req = opensocial.newDataRequest();
var mylink = document.getElementById("input_comm").value;
aff = mylink;
var json = gadgets.json.stringify(mylink);

req.add(req.newUpdatePersonAppDataRequest("VIEWER", "thefield",
json));
req.send(requestComm);
}

function requestComm() {
var req = opensocial.newDataRequest();
var fields = [ "thefield" ];


req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER),
"viewer");
req.add(req.newFetchPersonAppDataRequest("VIEWER", fields),
"viewer_data");
req.send(handleRequestComm);
}

function handleRequestComm(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
doSomethingWithComm(mydata.getData());
}

function doSomethingWithComm(data) {
//Data is indexed by user id, and represents an object where
keys
//correspond with the app data fields.
var mydata = data[me.getId()]["thefield"];
var ow = gadgets.util.unescapeString(mydata);
aff = gadgets.json.parse(ow);

document.getElementById('content_div').innerHTML += aff + "<br />";
}
</script>

this code,
does not work, help !!!

Rohit Ghatol (Google)

unread,
Jul 1, 2008, 8:23:28 AM7/1/08
to Orkut Developer Forum
Hi,
We have one example for storing a list and getting it back. This
example was written for code run. Could you use this code as the
reference?

One obvious thing, I can see in your code is that you are not using
gadgets.util.escapeString() and gadgets.utils.unescapeString()
functions.

function storeData(){
var list=["apple","banana","orange"];
var json = gadgets.util.escapeString(gadgets.json.stringify(list));


var req = opensocial.newDataRequest();
req.add(req.newUpdatePersonAppDataRequest("VIEWER",
"thefield",json));
req.send(getData);

}
function getData(data){
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest("VIEWER"),"viewer");
req.add(req.newFetchPersonAppDataRequest("VIEWER",
"thefield"),"viewerData");
req.send(displayData);

}

function displayData(response){
var person=response.get("viewer").getData();
var
theFieldValue=gadgets.util.unescapeString(response.get("viewerData").getData()
[person.getId()].thefield);

var obj=gadgets.json.parse(theFieldValue);
alert(obj);


}


storeData();


Thanks,
Rohit
Reply all
Reply to author
Forward
0 new messages