Skip to content

Instantly share code, notes, and snippets.

Last active December 15, 2015 20:19
Show Gist options
  • Save miniplay/5317335 to your computer and use it in GitHub Desktop.
Save miniplay/5317335 to your computer and use it in GitHub Desktop.
API loading for external games. Miniplay Connect DEMO.
/* NOTICE: For miniplay connect to work, your domain must be allowed by us, contact us to request access */
/* 1. Parameters decoding ============================================================================================ */
/* Only if your system configuration or language doesn't automatically decodes it */
foreach ($_GET as $key => $value) $_GET[$key] = urldecode($value);
/* 2. Parameters validation (mp_*) =================================================================================== */
/* External games doesn't receive neither parameters or signature, no validation needed */
/* 3. Known received parameters from Miniplay Connect ================================================================ */
$api_user_id = !empty($_GET['mp_api_user_id']) ? $_GET['mp_api_user_id'] : null;
$api_user_token = !empty($_GET['mp_api_user_token']) ? $_GET['mp_api_user_token'] : null;
$api_js_url = "";
$api_id = "## YOUR API ID ##"; /* Numeric, public ID of your API. DO NOT PUT YOUR PRIVATE API KEY HERE! */
<!-- ## YOUR OWN HEAD ## -->
<?php if ($api_js_url && $api_id):?>
<!-- Load MINIPLAY JS API! -->
<script id='LeChuckAPIjs' src="<?php echo $api_js_url;?>"></script>
<script type='text/javascript'>
lechuck = new LeChuckAPI({
id: "<?php echo $api_id;?>",
user_id: "<?php echo $api_user_id?>",
user_token: "<?php echo $api_user_token?>",
locale: "es_ES" /* Locale to use for Miniplay connect, check API docs for supported locales */
<?php endif;?>
<h1>Miniplay JS API external operation: A very basic demo showing the initialization & the guest user handling</h1>
<div id='status-msg'></div>
<div id='game' style='display:none'>
## Your game content for registered users (or it can be a dynamically attached iframe!) ##
Logged-in user: <span id='game-user'></span>
<div id='game-guest' style='display:none'>
Sorry, only for registered users!. <a href='' onclick='lechuck.user.login();return false;'>Login or register!</a>
<script type='text/javascript'>
var status_msg = document.getElementById('status-msg');
var game = document.getElementById('game');
var game_guest = document.getElementById('game-guest');
// Check if the API instance exists
if (lechuck instanceof Object) {
// Attach an onReady event listener to be dispatched once the api is ready!
// if the api is ready it will be automatically dispatched {
if(lechuck.user.isGuest()) {"block"; // Show guest message
} else {"block"; // Show game! (or load it)
document.getElementById('game-user').innerHTML = "#" + lechuck.user.getId() + " " +
lechuck.user.getUid() + " <img src='"+lechuck.user.getAvatarMini()+"'>";
}"none"; // Hide status message
// Initializing api...
status_msg.innerHTML = "Loading...";
} else {
status_msg.innerHTML = "API not loaded :(";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment