DmitrMakeev commited on
Commit
a3fa44e
·
verified ·
1 Parent(s): 50829b3

Update pages.html

Browse files
Files changed (1) hide show
  1. pages.html +58 -3
pages.html CHANGED
@@ -938,8 +938,7 @@ z-index: 1000; /* Убедитесь, что кнопка находится п
938
  <div class="mod_vk" id="vkid-container"></div>
939
 
940
 
941
-
942
- <script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
943
  <script type="text/javascript">
944
  if ("VKIDSDK" in window) {
945
  const VKID = window.VKIDSDK;
@@ -972,13 +971,69 @@ z-index: 1000; /* Убедитесь, что кнопка находится п
972
 
973
  function vkidOnSuccess(data) {
974
  // Обработка полученного результата
 
 
 
 
 
 
 
 
 
 
975
  }
976
 
977
  function vkidOnError(error) {
 
978
  // Обработка ошибки
979
  }
980
- </script>
981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
982
 
983
 
984
 
 
938
  <div class="mod_vk" id="vkid-container"></div>
939
 
940
 
941
+ <script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
 
942
  <script type="text/javascript">
943
  if ("VKIDSDK" in window) {
944
  const VKID = window.VKIDSDK;
 
971
 
972
  function vkidOnSuccess(data) {
973
  // Обработка полученного результата
974
+ console.log('VKID Success:', data);
975
+
976
+ // Сохранение токена в localStorage
977
+ localStorage.setItem('vkidAccessToken', data.access_token);
978
+
979
+ // Получение информации о пользователе
980
+ getVkUserInfo(data.access_token);
981
+
982
+ // Остановка редиректа
983
+ // Если вы хотите остановить редирект, просто не выполняйте window.location.href
984
  }
985
 
986
  function vkidOnError(error) {
987
+ console.error('VKID Error:', error);
988
  // Обработка ошибки
989
  }
 
990
 
991
+ function getVkUserInfo(token) {
992
+ // Запрос к API ВКонтакте для получения информации о пользователе
993
+ fetch('https://api.vk.com/method/users.get?v=5.131&access_token=' + token)
994
+ .then(response => {
995
+ if (!response.ok) {
996
+ throw new Error('Network response was not ok ' + response.statusText);
997
+ }
998
+ return response.json();
999
+ })
1000
+ .then(data => {
1001
+ if (data.response && data.response.length > 0) {
1002
+ const userInfo = data.response[0];
1003
+ console.log('User ID:', userInfo.id);
1004
+ sendRequestWithUserId(userInfo.id); // Отправить запрос с ID пользователя
1005
+ } else {
1006
+ console.error('Failed to get user info:', data);
1007
+ }
1008
+ })
1009
+ .catch(error => {
1010
+ console.error('Error getting user info:', error);
1011
+ });
1012
+ }
1013
+
1014
+ function sendRequestWithUserId(userId) {
1015
+ // Пример отправки запроса с ID пользователя
1016
+ fetch('https://your-api-endpoint.com/some-resource', {
1017
+ method: 'POST',
1018
+ headers: {
1019
+ 'Content-Type': 'application/json'
1020
+ },
1021
+ body: JSON.stringify({ userId: userId })
1022
+ })
1023
+ .then(response => {
1024
+ if (!response.ok) {
1025
+ throw new Error('Network response was not ok ' + response.statusText);
1026
+ }
1027
+ return response.json();
1028
+ })
1029
+ .then(data => {
1030
+ console.log('Response from API:', data);
1031
+ })
1032
+ .catch(error => {
1033
+ console.error('Error sending request:', error);
1034
+ });
1035
+ }
1036
+ </script>
1037
 
1038
 
1039