0

I load kongregate_api script in the head of the html document like this

<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>

Then loading my main.js script that contains these lines

    console.log(window.kongregateAPI)
    window.kongregateAPI.loadAPI(function () {});

screenshot of a part of main.js

The error message;

SyntaxError: An invalid or illegal string was specified in kongregate_api.js:36

console.log returns and object so i think it loads the script successfully.

screenshot of console logs

ankr
  • 647
  • 6
  • 15

1 Answers1

-1

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

Bivin Vinod
  • 2,210
  • 1
  • 12
  • 15
  • This is exactly how it is decribed in the kongregate javascript api page. But i still can not see the problem in my code. [Kongregate JS API Page](https://docs.kongregate.com/docs/javascript-api) – cezikmertcan Aug 19 '19 at 15:52