Esempio n. 1
0
        public List <Group> GroupFill(List <int> groupIdList)
        {
            int          num       = 400;
            List <Group> groupList = new List <Group>();
            double       count     = groupIdList.Count / num + 1;

            for (int i = 0; i <= count; i++)
            {
                string ids     = "";
                int    idCount = 0;
                for (int j = num * i; j < num + (num * i) && j < groupIdList.Count; j++)
                {
                    if (j % num == 0)
                    {
                        ids = ids + groupIdList[j];
                        idCount++;
                    }
                    else
                    {
                        ids = ids + "," + groupIdList[j];
                        idCount++;
                    }
                }
                string url      = String.Format("https://api.vk.com/method/groups.getById.xml?group_ids={0}&fields=place,description,members_count,city", ids);
                string xmlGroup = AuthorizationController.SendGet(url);
                GroupParse(xmlGroup, idCount);
            }
            return(groups);
        }
        public void Authorization(string token, int u_id)
        {
            string url     = String.Format("https://api.vk.com/method/users.get.xml?user_ids={0}&fields=photo_50", u_id);
            string xmlUser = AuthorizationController.SendGet(url);

            access_token = token;
            user_id      = u_id;
            Users user = UserParse(xmlUser);

            Session["user"] = user;
            RedirectToAction("Home", "Index");
        }
Esempio n. 3
0
        public JsonResult GetData()
        {
            if (q == null)
            {
                return(null);
            }
            Users        userA        = (Users)Session["user"];
            List <int>   groupIdListA = new List <int>();
            List <Group> groupsListA  = new List <Group>();

            if (areaType != "3")
            {
                int offset = 0;
                while (true)
                {
                    string url       = String.Format("https://api.vk.com/method/groups.search.xml?q={0}&type={1}&v=5.52&access_token={2}&count=1000&offset={3}&country_id=1", q, type, userA.accessToken, offset);
                    string xmlGroups = AuthorizationController.SendGet(url);
                    offset += 1000;
                    HtmlNodeCollection nodeOfIds = SelectNodes(xmlGroups, "//id");
                    if (nodeOfIds != null)
                    {
                        foreach (HtmlNode g in nodeOfIds)
                        {
                            groupIdListA.Add(int.Parse(g.InnerHtml));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                groupsListA = GroupFill(groupIdListA);
            }
            else if (areaType == "3")
            {
                string             urlA       = String.Format("https://api.vk.com/method/database.getCities.xml?country_id=1&q={0}&count=1000", areaCity);
                string             xmlCityA   = AuthorizationController.SendGet(urlA);
                HtmlNodeCollection nodeOfIdsA = SelectNodes(xmlCityA, "//cid");
                if (nodeOfIdsA != null)
                {
                    foreach (HtmlNode g in nodeOfIdsA)
                    {
                        cities.Add(g.InnerHtml);
                    }
                }
                // Получение xml-файла со списком групп
                foreach (string city in cities)
                {
                    string             url       = String.Format("https://api.vk.com/method/groups.search.xml?q={0}&type={1}&v=5.52&access_token={2}&city_id={3}&count=500", q, type, userA.accessToken, city);
                    string             xmlGroups = AuthorizationController.SendGet(url);
                    HtmlNodeCollection nodeOfIds = SelectNodes(xmlGroups, "//id");
                    // Получение id групп
                    if (nodeOfIds == null)
                    {
                        continue;
                    }
                    foreach (HtmlNode g in nodeOfIds)
                    {
                        groupIdListA.Add(int.Parse(g.InnerHtml));
                    }
                }
                // Создание коллекции групп
                groupsListA = GroupFill(groupIdListA);
            }
            q1 = q;
            Session["flag"] = true;
            System.IO.File.WriteAllLines(@"D:\GroupList.txt", otherGroups);
            return(Json(groupsListA, JsonRequestBehavior.AllowGet));
        }