There are some script errors in this code that need to be fixed first. You have to close the array being declared as "recipients". Also, what you're doing with declaring dataRequest as a variable, redefining it as a function, then internally reassigning it to an instance of a DataRequest is going to cause you trouble. It's legal code, but is a bear to maintain and debug. Additionally, the object MyOpenSpace.DetailType is coming up undefined when I step the code, which is causing an exception to be thrown prior to performing the request. I'd also encourage you to initialize the recipient list by registering the dataRequest initializer function with gadgets.util.registerOnLoadHandler instead of making a direct inline call. Additionally, the ID you're using to get the friends does not work with 0.8. The call to create the newFetchPeopleRequest is failing because opensocial.DataRequest.Group.VIEWER_FRIENDS is not defined. You need to use the idSpec object instead. You are also using an anonymous data request. You're much better off specifying a key so you can more easily retrieve the data.
Once I got through the main errors that were throwing exceptions, I found your paging to be wrong. Paging must start from 1, not zero. Once all that was fixed, the scope on your recipients array was wrong. It was declared in the callback handler, so was undefined when the rsaWrapper function called. You need to scope it to the window object
The full OpenSocial Javascript docs may be found at opensocial.org.
http://wiki.opensocial.org/index.php?title=JavaScript_API_Reference
I would encourage you to use Firefox 3.5 with the latest Firebug, or to use IE8 with the built-in script debugger to trace these kinds of issues. Inserting a debugger; statement in the code will trigger the debugger to launch and break. Most of your frustration is probably coming from using objects from the wrong OpenSocial version. Also, don't use document.write. It has horrible performance and clears your page contents, which I don't think is what you want. Use the DOM api instead.
Soooooo. Since I took the time to trace all this, here is the updated source code. This is 0.8 compliant (you should no longer be using 0.7 anyway). Some of the examples on the site are from 0.7, so this is another gotcha.
---------------
<Multiple Invites>
<script type='text/javascript'>
//debugger;
var os;
var friendDataRequest;
function initDataRequest()
{
//debugger;
os = opensocial.Container.get();
friendDataRequest= os.newDataRequest();
var friendsParams = {
}
;
friendsParams[ opensocial.DataRequest.PeopleRequestFields.FILTER ] = opensocial.DataRequest.FilterType.ALL;
friendsParams[ opensocial.DataRequest.PeopleRequestFields.FIRST] = 1;
friendsParams[ opensocial.DataRequest.PeopleRequestFields.MAX ] = 10;
/*
friendsParams[ MyOpenSpace.DetailType.GET_ONLINE ] = true;
friendsParams[ MyOpenSpace.DetailType.GET_STATUS ] = true;
friendsParams[ MyOpenSpace.DetailType.GET_MOOD ] = true;
*/
var idparams = {};
idparams[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;
idparams[opensocial.IdSpec.Field.GROUP_ID] = opensocial.IdSpec.GroupId.FRIENDS;
var id = opensocial.newIdSpec(idparams);
var FRIENDSReq = os.newFetchPeopleRequest(id, friendsParams);
friendDataRequest.add(FRIENDSReq, "friends");
friendDataRequest.send(getResponse);
}
var recipients = [;
function getResponse(response)
{
//debugger;
if( response.hadError() )
{
writeMessage(response.getErrorMessage());
return;
}
var VIEWER_FRIENDS = response.get("friends").getData().asArray();
for(var i=0; i gt;");
}
}
function multipleRSAWrapper(){
//debugger;
// create the rSA message
var body = "Hey [recipient]! [sender] wants you to ";
body += "add [app]. It's way awesome!";
// create an opensocial.Message object
var reason = opensocial.newMessage(body);
// initiate requestShareApp
opensocial.requestShareApp(recipients, reason, function(){ writeMessage('gt; SENT INVITES'); });
}
function writeMessage(msg){
var elem = document.getElementById('msg');
if(elem){
elem.innerHTML += msg
}
}
gadgets.util.registerOnLoadHandler(initDataRequest);
</script>
<button onclick="multipleRSAWrapper();" >Multi Invite</button>
<div id="msg"> </div>