Loading the API
In order to load the Kongregate API object, you need to include a script tag which loads our JavaScript source file. The script tag should be placed inside the head section of your document.
HTML
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>
Initializing the API
The JavaScript API automatically creates a global variable named kongregateAPI. You can use this object to initialize the Kongregate API services with the loadAPI and the getAPI functions:
Example: Load the API, and set up a global reference to the API object named kongregate function once initialized.
JAVASCRIPT
kongregateAPI.loadAPI(function(){
window.kongregate = kongregateAPI.getAPI();
// You can now access the Kongregate API with:
// kongregate.services.getUsername(), etc
// Proceed with loading your game...
});
Note
The API should only be loaded/initialized once per Kongregate game page load. If your application spans multiple pages/documents, please see the documentation on the Kongregate Shell for information on setting up and accessing a persistent API connection