S
S
SetAres2016-04-21 17:15:55
In contact with
SetAres, 2016-04-21 17:15:55

Retrying users.search in a loop after an offset returns an incomplete response. What's wrong?

I get the number of users from the request. If there are more than 1000 of them (and there are 21215 of them), then in the loop I try to use the offset to bring everyone into dataGridView3

// получил количество пользователей
... 
if (user_count > 1000)
                {
                    do
                    {
                        USER_ID = GET_http(String.Format("https://api.vk.com/method/users.search.xml?" + request + "&offset=" + offset + "&count=1000&fields=photo_id&access_token={0}", Settings1.Default.token));
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(USER_ID);

                        XmlNodeList items = doc.SelectNodes("response/user/uid");

                        
                        foreach (XmlNode item in items)
                        {
                            k++;
                            if (item.LocalName == "uid")
                                dataGridView3.Rows.Add(item.FirstChild == null ? "" : k + ") " + item.FirstChild.Value, (item.NextSibling.InnerText == null ? "" : item.NextSibling.InnerText) + " " + (item.NextSibling.NextSibling.InnerText == null ? "" : item.NextSibling.NextSibling.InnerText), item.NextSibling.NextSibling.NextSibling == null ? "" : (item.NextSibling.NextSibling.NextSibling.InnerText == null ? "" : item.NextSibling.NextSibling.NextSibling.InnerText));
                        }
                        offset += 1000;
                        user_count -= 1000;

                        System.Threading.Thread.Sleep(50);
                    }
                    while (user_count > 0);

                }

The first loop returns a normal response in the format with ID, first_name, last_name.
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response list=\"true\">\n <count>21215</count>\n <user>\n  <uid>ид человека</uid>\n  <first_name> Имя </first_name>\n  <last_name>Фамилия</last_name>\n  <photo_id>ид фотки</photo_id>\n </user>\n ..... </response>\n"

In the second pass of the do while loop, after an offset of 1000, a query like this is returned:
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response list=\"true\">\n <count>21215</count>\n</response>\n"
. After the offset, the number of group members is returned, but ID, first_name, last_name are returned. D What could be the problem?
This sequence of queries produces the same result. The first answer is complete, the second is only the number of participants.
USER_ID = GET_http(String.Format("https://api.vk.com/method/users.search.xml?" + request + "&offset=0&count=1000&fields=photo_id&access_token={0}", Settings1.Default.token));
USER_ID = GET_http(String.Format("https://api.vk.com/method/users.search.xml?" + request + "&offset=1000&count=1000&fields=photo_id&access_token={0}", Settings1.Default.token));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2016-04-21
@SetAres

https://new.vk.com/dev/users.search
If you are looking for a group, then you should use https://new.vk.com/dev/groups.getMembers
And go through the filter already inside your application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question