?
?
?2020-01-31 20:39:59
Python
?, 2020-01-31 20:39:59

Name vk_api python, how to get it?

Hello. I would like to ask for help. I want my auto-responder bot to respond to the name of the person who wrote to me. For example:


Some Anton, for example: Hello!
Bot: Hi Anton! ...


I would be very grateful, because I can not find a clear answer anywhere. :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alternativshik, 2020-01-31
@alternativshik

Lord, open the dock on the VK API and read - everything is written in Russian there.

L
lumpenkoder, 2020-01-31
@lumpencoder

The username can be obtained through from_id , which can be obtained from the object coming from VK. You make a request to the users.get method, where you specify from_id in the user_ids parameter . Then, from the response array , you get the first_name field , the name is stored there. Sample Code

from_id = event.from_id # event - переменная прослушки запросов на ваш сервер от вк
resp = vk.method('users.get', {'user_ids': from_id}) # Запрос к вк апи
name = resp[0]['first_name'] # Получение имени

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question