More Information on requestShareApp
This is a follow-up on Kyle’s post “quick update on ACC” with some implementation details.
http://developer.myspace.com/community/blogs/devteam/archive/2008/06/30/quick-update-on-acc.aspx
* As Kyle mentioned this feature is not yet in production, but will be soon. We wanted to get out the implementation details now so when we're ready to turn it on, you will be too.
Invoking requestShareApp
First let’s take a look at the signature:
opensocial.requestShareApp(recipients, reason, opt_callback);
· recipients: this is a person’s friend ID. We currently only support sending in one ID at a time
· reason: this is the message you want sent. I’ll go over the rules for this below
· opt_callback: a callback function
Reason
The reason is an opensocial.Message object that has the text you’d like to have displayed in the invite set as the opensocial.Message.Field.BODY (which you can also pass into the constructor).
There are a few rules for the text:
· The text is limited to 150 characters – the character count does not include your application name or the sender and/or recipient display name. More on this below
· You can not include any HTML markup. Adding your links to your application, recipient and sender will be done by us.
· We have supplied three place holders you can use to add your application name, sender name and recipient name within links:
o [sender] – this will be transformed to a hyperlink with the senders display name as the text. The link will go to their profile.
o [app] – this will be transformed to a hyperlink with your application name as the text. The link will go to the applications profile.
o [recipient] – this will be transformed to a hyperlink with the recipients display name as the text. The link will go to their profile.
· You do not have to use all the placeholders. Example below.
Example Code
The code is pretty simple.
message = opensocial.newMessage("[sender] would like you to intall this really super application [app].");opensocial.requestShareApp(recipientUserId, message, function(){
alert('sent application invite');
}
);recipientUserId to be the userId of the recipent.
The stubs for requestShareApp are already in production so you can wire up your applications now. Since the call will fail you’ll want to hide the functionality until we turn things on.
There are two ways to check if SHARE_APP is enabled. One is to make the call to requestShareApp() and if it’s not enabled you’ll get an unsupported back. The second is to use getSupportedPostToTargets() to get a list of supported PostTo targets – this is not part of the OS spec, but because requestShareApp currently uses PostTo it’ll work.
function isPostToTargetLive(){
var supported = osContainer.getMySpaceEnvironment().getSupportedPostToTargets();
var isSupported = false;
for(var i = 0; i < supported.length; i++){
if(supported[ i ] === "SHARE_APP"){
isSupported = true;
break;
}
}
return isSupported;
}
D