x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <meta charset="utf-8" />
5
    <title>How to get token</title>
6
    <script type="text/javascript" src="//hst-api.wialon.com/wsdk/script/wialon.js"></script>
7
</head>
8
<body>
9
    <!-- Call getToken() onclick -->
10
    <input id="login" type="button" value="Click to open login page" onclick="getToken()"/>
11
    <!-- Print token here-->
12
    Your token: <span id="token"></span>
13
    <br /><br />
14
    <input id="logout" type="button" value="Click to logout" disabled onclick="logout()"/>
15
</body>
16
</html>
17
HTML
3
 
1
#token {
2
    font-weight: bolder;
3
}
CSS
58
 
1
// Wialon site dns
2
var dns = "https://hosting.wialon.com";
3
4
// Main function
5
function getToken() {
6
    // construct login page URL
7
    var url = dns + "/login.html"; // your site DNS + "/login.html"
8
    url += "?client_id=" + "App";   // your application name
9
    url += "&access_type=" + 0x100; // access level, 0x100 = "Online tracking only"
10
    url += "&activation_time=" + 0; // activation time, 0 = immediately; you can pass any UNIX time value
11
    url += "&duration=" + 604800;   // duration, 604800 = one week in seconds
12
    url += "&flags=" + 0x1;         // options, 0x1 = add username in response
13
    
14
    url += "&redirect_uri=" + dns + "/post_token.html"; // if login succeed - redirect to this page
15
16
    // listen message with token from login page window
17
    window.addEventListener("message", tokenRecieved);
JS
Result
Source code of example Close ✕
1
 
1
/*source*/