Answer the question
In order to leave comments, you need to log in
How to fix list indices must be integers or slices, not str error when getting username?
I'm trying to get the name using the users.get method, but for some reason it doesn't work.
here is the code:
userget = vk.users.get(user_ids = 1)
name = userget["first_name"]
print(name)
Answer the question
In order to leave comments, you need to log in
userget = vk.users.get(user_ids=1)
name = userget[0]["first_name"]
print(name)
The function vk.users.get()
returned you a list. List elements are accessed by index, not by key.
Use the py-vkontakte library
>>> import vk
>>> api = vk.Api('YOUR_TOKEN')
>>> user = api.get_user('durov')
>>> user.first_name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question