I
I
Ivan2016-01-22 09:37:27
In contact with
Ivan, 2016-01-22 09:37:27

How to display user id after VK API authorization via Widget?

Actually, I need the user ID of the authorized user to be displayed in a pop-up window after Vkontakte authorization.
Test site inf2.ru
code is as follows:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="jquery.js"></script>
  <script src="http://userapi.com/js/api/openapi.js" type="text/javascript" charset="windows-1251"></script>
<script src="//vk.com/js/api/openapi.js" type="text/javascript"></script>
<script language="javascript">
VK.init({
  apiId: 5237076
});
</script>
</head>
<body>
<div id="vk_auth" style="display: none;"></div>
<script type="text/javascript">
$(document).ready(function() {


VK.Widgets.Auth("vk_auth", {width: "200px", authUrl: 'http://inf2.ru/index.php', onAuth: function(data) 
      {
      location.reload();
      } 
    });


VK.Auth.getLoginStatus(function(response) { 
  if (response.session) { 
    /* Авторизованный в Open API пользователь */ 
  } else { 
$('#vk_auth').css('display','block');
  } 
}); 



 VK.Api.call('users.get', {}, function(r) {
    alert('Привет, ' + r.response[0].uid);
});  


 


});

</script>

</body>
</html>

After authorization, an unauthorized user does not show iD, you have to reload the page to show it. How to make it show without reboot?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question