-
Notifications
You must be signed in to change notification settings - Fork 21
/
send-simple.html
71 lines (60 loc) · 2.44 KB
/
send-simple.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<meta charset="UTF-8">
<title>OKSDK - REST notifications.sendSimple (nosession)</title>
<script type="text/javascript" src="../oksdk.js"></script>
</head>
<body>
<div id="backBtn"></div>
<div id="content" style="display: none;">
<p>
WARNING: This is just a sample (of REST method calling without active session using OKSDK).
In real game, storing application secret key inside your JS client app is prohibited due to
easy way to steal it and use for spamming purposes. Such methods should only be called from
game server instead.
<br/>
<input type="button" onclick="sendSimple();" value="Send simple message"/><br/>
Posts a simple "hello world!" notification
</p>
</div>
<script type="text/javascript">
var currentUserUID = 0;
function sendSimple() {
OKSDK.REST.call("notifications.sendSimple",
{uid: currentUserUID, text: 'Hello world from oksdk.js!'},
function (status, data, error) {
if (status == 'ok') {
alert('SendSimple sent ok: ' + OKSDK.Util.toString(data));
} else {
alert('Error with send simple to user ' + currentUserUID + ': ' + OKSDK.Util.toString(error));
}
},
{no_session: true, app_secret_key: '' /* <-- insert APP SECRET KEY here */}
);
}
document.addEventListener('DOMContentLoaded', function () {
var config = {
app_id: 0, // <-- insert APP ID here
app_key: '' // <-- insert APP PUBLIC KEY here
};
OKSDK.init(config, function () {
OKSDK.Widgets.getBackButtonHtml(function (html) {
document.getElementById('backBtn').innerHTML = html;
});
document.getElementById('content').style.display = '';
OKSDK.REST.call("users.getCurrentUser",
{fields: "UID"},
function (status, data, error) {
if (status == 'ok') {
currentUserUID = data.uid;
} else {
alert('Error with retrieving current user ' + OKSDK.Util.toString(error));
}
});
}, function (error) {
alert('OKSDK error' + OKSDK.Util.toString(error));
})
});
</script>
</body>
</html>