T
T
TechNOIR2017-10-27 13:07:34
PowerShell
TechNOIR, 2017-10-27 13:07:34

Powershell+VK API. How to bypass the limit of 1000 objects?

Good day, comrades!
Help please with a problem.
I sketched a script for working with the VK API, but I can’t get around the limit on the number of objects.
Can you tell me if there are any errors in the script? I'm already stuck..

$i = 0
$uri = "https://api.vk.com/method/users.search?education_form='Очное отделение'&university_year=2019&graduation=2019&country=1&university_country=1&fields=domain&count=900&out=1&offset="+$i+"&access_token=03bdb304a427de9d761ae22c008d7a1995f2fcd2a5fae4dd5f4e2b3ae457fa2c1f8bf665cdfe6ec5ac107&v=5.68"
$request = Invoke-WebRequest -Uri $uri
$response_array = $request.content | ConvertFrom-Json 
$request_count = $response_array.response.count
"Всего: " + $request_count
#$result = $null
$request_array = $null

for ($i = 0; $i -le $request_count ; $i=$i+900)
{ 
write-host $i
$uri = "https://api.vk.com/method/users.search?education_form='Очное отделение'&university_year=2019&graduation=2019&country=1&university_country=1&fields=domain&count=900&out=1&offset="+$i+"&access_token=03bdb304a427de9d761ae22c008d7a1995f2fcd2a5fae4dd5f4e2b3ae457fa2c1f8bf665cdfe6ec5ac107&v=5.68"
write-host $uri
$request = Invoke-WebRequest -Uri $uri
$response_array = ($request.content | ConvertFrom-Json).response.items
$request_array = $request_array + $response_array
write-host("Получаем $i")
Start-Sleep -m 340    
}

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Serezha, 2017-10-27
@TechNOIR

Please note that even when using the offset parameter, only the first 1000 results are available to get information.

Play around with the parameters, in particular, it should be enough -
sort - run twice with different sorting types
sex - run twice with different sex
age_from, age_to - run as many times as you like Bottom
line - we change the search parameters and get a new list of users, different from the previous ones results. We glue the lists and remove duplicates.
It seems to me that several combinations of the sex and age_to parameters will be enough (for example, male gender - age up to 20, male gender - age from 20 to 30, male gender - age from 30, repeat the combinations with the female gender).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question