E
E
Egor Tomashin2020-10-28 11:55:34
In contact with
Egor Tomashin, 2020-10-28 11:55:34

Getting the First Name, Last Name and User ID through the VK API - how to implement?

It is required to get the user id (well, first name / last name). The VK API is initialized normally, here is the code for the https://vk.com/dev/account.getProfileInfo method

VK.api("account.getProfileInfo", function (data) {
                alert("Info: " + data.first_name + " " + data.last_name + " " + data.id);
                console.log("Info: " + data.first_name + " " + data.last_name + " " + data.id);
                returnStr = data.id;
            });

Everywhere (both in the alert and in the console) returns "Info: undefined undefined undefined".
What is wrong, or how to get the right data?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Tomashin, 2020-10-28
@tomashined

Solution - code to get ID

VK.api("users.get", {"v":"5.124"}, function (data) {
                var id = data["response"][0]["id"];
                returnStr = id;
            });

Important - it is necessary that the state of the application be "The application is enabled and visible to everyone."

A
Anton Shamanov, 2020-10-28
@SilenceOfWinter

This method can be called with a user access key obtained in the Standalone application via Implicit Flow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question