Update user.html
Browse files
user.html
CHANGED
@@ -3,29 +3,10 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
7 |
-
|
8 |
-
<style>
|
9 |
-
body {
|
10 |
-
font-family: Arial, sans-serif;
|
11 |
-
text-align: center;
|
12 |
-
background-color: #02a612;
|
13 |
-
margin: 0;
|
14 |
-
padding: 0;
|
15 |
-
display: flex;
|
16 |
-
justify-content: center;
|
17 |
-
align-items: center;
|
18 |
-
height: 100vh;
|
19 |
-
}
|
20 |
-
.vkid-container {
|
21 |
-
width: 360px;
|
22 |
-
height: 56px;
|
23 |
-
margin: auto;
|
24 |
-
}
|
25 |
-
</style>
|
26 |
</head>
|
27 |
<body>
|
28 |
-
|
29 |
<script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
|
30 |
<script type="text/javascript">
|
31 |
if ("VKIDSDK" in window) {
|
@@ -37,14 +18,21 @@
|
|
37 |
"source": VKID.ConfigSource.LOWCODE,
|
38 |
});
|
39 |
|
40 |
-
const
|
41 |
|
42 |
-
|
43 |
-
"
|
44 |
-
"showAlternativeLogin": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
})
|
46 |
.on(VKID.WidgetEvents.ERROR, vkidOnError)
|
47 |
-
.on(VKID.
|
48 |
const code = payload.code;
|
49 |
const deviceId = payload.device_id;
|
50 |
|
@@ -55,13 +43,33 @@
|
|
55 |
}
|
56 |
|
57 |
function vkidOnSuccess(data) {
|
58 |
-
|
|
|
|
|
|
|
59 |
}
|
60 |
|
61 |
function vkidOnError(error) {
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
</script>
|
65 |
-
</div>
|
66 |
</body>
|
67 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>VK Authorization</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
</head>
|
8 |
<body>
|
9 |
+
<div id="vkid-container"></div>
|
10 |
<script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
|
11 |
<script type="text/javascript">
|
12 |
if ("VKIDSDK" in window) {
|
|
|
18 |
"source": VKID.ConfigSource.LOWCODE,
|
19 |
});
|
20 |
|
21 |
+
const oneTap = new VKID.OneTap();
|
22 |
|
23 |
+
oneTap.render({
|
24 |
+
"container": document.getElementById('vkid-container'),
|
25 |
+
"showAlternativeLogin": true,
|
26 |
+
"styles": {
|
27 |
+
"width": 360
|
28 |
+
},
|
29 |
+
"oauthList": [
|
30 |
+
"ok_ru",
|
31 |
+
"mail_ru"
|
32 |
+
]
|
33 |
})
|
34 |
.on(VKID.WidgetEvents.ERROR, vkidOnError)
|
35 |
+
.on(VKID.OneTapInternalEvents.LOGIN_SUCCESS, function (payload) {
|
36 |
const code = payload.code;
|
37 |
const deviceId = payload.device_id;
|
38 |
|
|
|
43 |
}
|
44 |
|
45 |
function vkidOnSuccess(data) {
|
46 |
+
const accessToken = data.access_token;
|
47 |
+
console.log('Access Token:', accessToken);
|
48 |
+
// Используем токен для выполнения запросов к API ВКонтакте
|
49 |
+
getVkUserInfo(accessToken);
|
50 |
}
|
51 |
|
52 |
function vkidOnError(error) {
|
53 |
+
console.error('VKID Error:', error);
|
54 |
+
}
|
55 |
+
|
56 |
+
function getVkUserInfo(token) {
|
57 |
+
const url = `https://api.vk.com/method/users.get?v=5.131&access_token=${token}`;
|
58 |
+
fetch(url)
|
59 |
+
.then(response => response.json())
|
60 |
+
.then(data => {
|
61 |
+
if (data.response && data.response.length > 0) {
|
62 |
+
const userId = data.response[0].id;
|
63 |
+
console.log('User ID:', userId);
|
64 |
+
// Используем полученный ID пользователя для дальнейших действий
|
65 |
+
} else {
|
66 |
+
console.error('Failed to get user info:', data);
|
67 |
+
}
|
68 |
+
})
|
69 |
+
.catch(error => {
|
70 |
+
console.error('Error:', error);
|
71 |
+
});
|
72 |
}
|
73 |
</script>
|
|
|
74 |
</body>
|
75 |
</html>
|