Answer the question
In order to leave comments, you need to log in
How to get username using VK.api for iframe application?
Hello!
Recently I started to study VK.api, started small and immediately got the first task: how to get the Username? Maybe I wrote something wrong? Who knows the solution, please suggest.
<!DOCTYPE html>
<html>
<head>
<script src="https://vk.com/js/api/xd_connection.js?2" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
var myid = document.getElementById("text");
var ids = <?php echo $_GET["viewer_id"]; ?>;
VK.api("users.get", {user_ids: ids}, function(data) {
alert(data.response[0].first_name);
});
myid.innerHTML = ids;
};
</script>
<div id="text"></div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
I found the answer myself, thank you all for your attention)) Below I will write a fully working code (for my case), which will display the user's last name. But the error itself was not in the code, but in the application status settings, it was "Disabled and visible only to the developer", so the request code did not work, and I fought for 2 days ... Everything works when the status of your iframe is open. By the way, I didn’t find an answer on all the Internet, examples are slipping in php, python, but not js, and if there is, then in 2012, and the methods have already changed)) In general, use whoever needs it:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<script src="https://vk.com/js/api/xd_connection.js?2" type="text/javascript"></script>
<script type="text/javascript">
VK.init(function(){
alert("good");
}, function(){
alert("bad");
}, '5.62');
</script>
<script type="text/javascript">
VK.api("users.get", {'user_ids' : 1}, function(data) {
console.log(data.response[0].last_name);
});
</script>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question