API Reference
From MobileGuard
Contents |
JavaScript API
The API is available for OpenSocial and Facebook applications. OpenSocial applications use the same library version as Facebook Iframe applications. Facebook FBML applications use the alternate library version. Both versions define the mobileguard namespace.
OpenSocial / Facebook Iframe Version:
<script src="http://api.mobileguard.org/Main.ashx" type="text/javascript" ></script>
FBML Version :
<script src="http://api.mobileguard.org/fbmain.ashx" type="text/javascript" ></script>
mobileguard namespace
Both API versions contain the same public API in the mobileguard namespace, which is only two functions and two variables.
mobileguard.ownsFeature(userid, featurekey, callback)
Determines if the user identified by userid owns the provided featurekey.
| Parameter | Type | Description | |
| userid | string | Unique identifier of the user on the given appDomain | |
| featurekey | Number | Unique identifier provided by MobileGuard for the current application | |
| callback | function | Callback function that is called with the appropriate responseCode |
Returns: mobileguard.responseCode
mobileguard.gotoOptin(URL)
Directs the user to the MobileGuard flow. This should only be called if ownsFeature() returns false.
| Parameter | Type | Description |
| URL | string | Where a user should return after the MobileGuard flow. This parameter is optional, and defaults to document.location.href. Note: This parameter is mandatory in the FBML library.
|
Returns: N/A, user is taken back to the provided URL
mobileguard.appDomain
String containing the social network domain of the current application, by default this is set to document.domain or facebook.com if fbmain.ashx is used. This value can be set if the domain from which the application is loaded doesn't match the domain of the social network it is being loaded from.
mobileguard.responseCode
| responseCode | Meaning |
| TRUE | The current User owns the application |
| FALSE | The Current user doesn't own the application and mobile guard is able to bill them |
| NOT_BILLABLE | The current user doesn't own the application and mobile guard isn't able to bill the user |
| ERROR | Mobile Guard encountered an error with your request |
Pre-loading viewer information
By loading the main client library with specific query string parameters, viewer information can be pre-loaded, which saves a request if the ownsFeature call is going to be made on the viewer.
Examples:
IFRAME version:
<script src="http://api.mobileguard.org/main.ashx?featurekey=99999&domain=hi5.com&userid=user1234" type="text/javascript" ></script>
FBML version:
<script src="http://api.mobileguard.org/fbmain.ashx?featurekey=99999&domain=hi5.com&userid=user1234" type="text/javascript" ></script>
Sample Code
<html>
<head>
<script type="text/javascript" >
function isOwned (){
mobileguard.ownsFeature(document.getElementById('userId').value,
document.getElementById('appId').value,
callbackfn);
}
function callbackfn(code){
switch(code){
case mobileguard.responseCodes.TRUE:
alert('Enjoy my sweet app!');
break;
case mobileguard.responseCodes.NOT_BILLABLE:
// Allow the user to use the app, or deny entry to allow in only paid users.
alert('Enjoy my sweet app!');
break;
case mobileguard.responseCodes.FALSE:
alert('Heading to the MoGu flow');
mobileguard.gotoOptin();
break;
case mobileguard.responseCodes.ERROR:
alert('Sorry, an error has occurred');
break;
default:
alert('Unexpected value passed in');
break;
}
}
</script>
<script src="http://api.mobileguard.org/Main.ashx" type="text/javascript" ></script>
</head>
<body >
<h1> MoGu test app </h1>
<span> Lorum Ipsem etc </span>
<br />
<input type='hidden' id='userId' value='user1234' /> <br />
<input type='hidden' id='appId' value='99999' /> <br />
<a href="javascript:isOwned();" > Can I Bill you? </a>
</body>
</html>
