Share gadget with friends (appInvite)

With this function it's possible to send an invite for sharing a gadget with friends.

The official API reference can be found here.

Restrictions on our implementation
  • We have adjusted this call to a dialogbox which is called and the window has to be granted by the viewer. The default reason of the invite is: "_displayname_ invites you to _gadget_title_".
  • When the dialog is closed without sending any invites (e.g. by pressing the X button), the callback function is also called, but the list of recipients will be an empty array.
  • Reason is not passed through
  • The "recipients" is only used to preselect up to 10 recipients. You get a selectbox with all your friends.
  • When testing this function within the Sandbox it's only possible to send application invites from API-partner to API-partner. Invites that are addressed to non API-partner Hyvers are not send.
Example of how to use requestShareApp

<?xml version="1.0" encoding="UTF-8"?>
<Module>
	<ModulePrefs title="RequestShareApp" description="" author="" author_email="" thumbnail="" screenshot="" height="380">
		<Require feature="opensocial-0.7"/>
		<Require feature="views"/>
	</ModulePrefs>
	<Content type="html">
	<![CDATA[
	<script type="text/javascript">
	var shareApp = function() {
		opensocial.requestShareApp([], 'This reason sentence is not used at the moment', requestShareAppCallback);
	}
	var requestShareAppCallback = function(responseItem) {
		if(responseItem.hadError()) {
			var sErrorcode = responseItem.getErrorCode();
			alert(sErrorcode);
		} else {
			// list of users that received the invite
			var aData = responseItem.getData();
			if(aData.length != 0) {
				for (i=0;i<aData.length;i++) {
					alert(aData[i]);
				} 
			} else {
				// No application invite send
			}
		}
	}
	var getViewer = function(responseItem) {
		if(responseItem.hadError()) {
			var sErrorcode = responseItem.getErrorCode();
			alert(sErrorcode);
		}
		if(opensocial.hasPermission(opensocial.Permission.VIEWER)) {
			shareApp();
		}
	}
	var isViewer = function() {	
		opensocial.requestPermission([opensocial.Permission.VIEWER], 'This reason sentence is not used at the moment', getViewer);	
	}
	</script>
	<input type="button" value="Call invite-box" onClick="isViewer();">
	]]>
	</Content>
</Module>

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

Example file