Question:
Tell me a way to quickly get the id of a VK user who visited my site.
I have a button, and by clicking on it, the VK window should appear, and after permission, I should get the id or immediately the name and url to the avatar picture.
Everything should be without reloading the page.
Answer:
<script src="//vk.com/js/api/openapi.js" type="text/javascript"></script>
<script type="text/javascript">
VK.init({
apiId: код приложения
});
function authInfo(response) {
if (response.session) {
console.log(response.session.mid);
}
}
VK.Auth.getLoginStatus(authInfo);
VK.Auth.login(authInfo);
</script>
To get access to the API, you need to register your application.