P
P
pruha192018-12-09 16:36:13
Python
pruha19, 2018-12-09 16:36:13

How to get the necessary data?

import vk
session = vk.Session()
api = vk.API(session, v = 5.8)
token = 'token'
id = 1
api.users.get(access_token = token, user_ids = id)

VK answer: [{'id': 1, 'first_name': 'Pavel', 'last_name': 'Durov'}]
How to get the necessary data (for example, first_name )
The answer needs to be detailed and understandable for a beginner :)
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Gilfanov, 2018-12-09
@pruha19

Check out the core Python collections.
Lists (list type):
https://pythonworld.ru/tipy-dannyx-v-python/spiski...
Dictionaries (dict type):
https://pythonworld.ru/tipy-dannyx-v-python/slovar. ..
Especially regarding the reference to the element of the list / dictionary by index.
Then you can do like this:

...
response = api.users.get(access_token = token, user_ids = id)
first_name = response[0]['first_name']
print(first_name)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question