D
D
doksketch2020-08-06 12:51:52
Python
doksketch, 2020-08-06 12:51:52

How to pass list of user_id to request vk api?

It is necessary to pass user_id in a list in a cycle to a request for api vk. Below is an example of the current implementation.

api_link = ' https://api.vk.com/method/ '
method = 'users.get'
id_links = [] #list from user_id
field_list = [] #list of returned fields by user
params = {'user_ids': id_links,
'fields': field_list,
'lang': 3,
'access_token': access_token,
'v': '5.120'} #request parameters

start = 0 # sampling start
step = 5 # loop step, it is the size of the list that is passed to query

for user in range(start, len(id_links), step):
params['user_ids'] = user_list

user_info = requests.get(api_link + method, params=params).json()

start += step
user += step

In the current implementation, every fifth user is returned, but it is necessary that 5 users be transmitted in one request.
What needs to be corrected?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-06
@doksketch

users_count = 5

for x in range(len(id_links) // users_count + 1):
    print(id_links[x*users_count:x*users_count+users_count])

Well, you will need to convert the list of people by separating them with commas through .join , a regular list will not work (probably).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question