VK.init({ apiId: 4850938 }); function authInfo(response) { if(response.status=='connected') { // если пользователь залогинен в ВК if (typeof(response.session.user) == 'undefined') { // этого поля нет //тогда, когда пользователь был залогинен ранее VK.Api.call('users.get', { uid: response.session.mid }, function(r) { $('#VKInfo').html(r.response[0].first_name+' '+r.response[0].last_name); $('#VKInfo').append('user_id: '+response.session.mid); }); } else { // если авторизация прошла только что (от VK.Auth.login(authInfo);), то имя и фамилия уже будут в ответе $('#VKInfo').html(response.session.user.first_name+' '+response.session.user.last_name); $('#VKInfo').append(.'user_id: '+response.session.mid); } } else { VK.Auth.login(authInfo); // опционально можем спалиться и вызвать всплывающее окно авторизации } } $(function() { VK.Auth.getLoginStatus(authInfo); }); // проверяем наличие входа в ВК, ответ отправляем в функцию обработчик 

And in <body> following:

 <span id="VKInfo"> </span> 

But in the end nothing comes to the span.

  • what prevents to write console.log(r) and see what comes in response? - Alexey Shimansky
  • one
    ......... well, in general, just a syntax error .append(.'user_id: ' ...... point before 'user_id ........... and this, by the way, can it was to learn also by opening a trite console - Alexey Shimansky
  • The only error in the console did not affect anything: openapi.js? 136: 434 Uncaught TypeError: Cannot read property 'insertBefore' of undefined (...) - Timur Musharapov
  • Oh, come on .... sure it was a mistake, it became another ...... and VK.init should be in the body . Surely you have everything hanging in your head somewhere - Alexey Shimansky
  • Yes, there was an error in <head>. Why in the <body>? - Timur Musharapov

0