Answer the question
In order to leave comments, you need to log in
How to get a person's name through vkapi?
if textl.lower() == 'кто я?':
try:
vk.messages.send(
peer_id=peer_id,
message=f"[id{from_id}|{имя человека который написал сообщение}]", #ответ бота
random_id=get_random_id(),
)
except Exception as e:
print ("Сообщение не отправленно")
Answer the question
In order to leave comments, you need to log in
Try debugging to find out the full path to the name.
For example, I do this: ["response"][0]["first_name"]
I hope you take something for yourself from this code:
info = requests.get('https://api.vk.com/method/users.get', params={
'v': v,
'name_case': 'Nom',
'access_token': token,
'fields': 'photo_max_orig,counters'
}).json()
if "error" in info:
print("[red]Неправильный токен[/red]")
sys.exit()
first_name = info["response"][0]["first_name"]
last_name = info["response"][0]["last_name"]
You use the users.get method with the id you need.
Without an additional request to the API in any way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question