Answer the question
In order to leave comments, you need to log in
How to get username VK.API Python?
I tried to create a bot that can address the user by first and last name. This code throws an error. If there is an easier way to get the username, I'd be happy to know it)
def get_name(from_id):
info = getting_api.users.get(user_ids = from_id)[0]
full_name = info.get('first_name') + ' ' + info['last_name']
return full_name
getting_api = authorize.get_api()
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
msg = event.text
from_id = event.message.get('from_id')
name = get_name(from_id)
if msg == 'test':
write_message(sender, name)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question