Esempio n. 1
0
        private int GetWallPostsCount(string wallPageName)
        {
            var          https    = new Https();
            var          count    = 0;
            const string method   = "wall.get";
            var          vkParams = new NameValueCollection
            {
                { "access_token", ServiceKey },
                { "v", "5.53" },
                { "domain", wallPageName }
            };
            var response = https.POST(ApiPage + method, new CookieContainer(), vkParams);

            try
            {
                count = int.Parse(JObject.Parse(response.Content)["response"]["count"].ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                MessageBox.Show("Неправильный адрес стены / страница не общедоступна");
                //throw;
            }


            return(count);
        }
Esempio n. 2
0
        private List <Tuple <string, string> > GetWallPostsImagesLinks(string wallPageName, int quantity)
        {
            var https = new Https();
            var links = new List <Tuple <string, string> >();

            const string method       = "wall.get";
            var          proceedCount = 0;

            while (proceedCount < quantity)
            {
                var curCount = quantity - proceedCount;
                if (curCount > 100)
                {
                    curCount = 100;
                }
                //else curCount = quantity - proceedCount;
                var vkParams = new NameValueCollection
                {
                    { "access_token", ServiceKey },
                    { "v", "5.53" },
                    { "domain", wallPageName },
                    { "count", curCount.ToString() },
                    { "offset", proceedCount.ToString() }
                };
                var response = https.POST(ApiPage + method, new CookieContainer(), vkParams);

                foreach (var jo in JObject.Parse(response.Content)["response"]["items"])
                {
                    if (jo["attachments"] == null)
                    {
                        continue;
                    }
                    var imgName    = "wallid" + jo["id"];
                    var tImageName = imgName;
                    var jj         = jo["attachments"] ?? jo["copy_history"]["attachments"];
                    var attCnt     = 1;
                    foreach (var jo1 in jj)
                    {
                        imgName += "_" + attCnt++;
                        if (!jo1["type"].ToString().Equals("photo"))
                        {
                            continue;
                        }
                        if (jo1["photo"]["photo_2560"] != null)
                        {
                            links.Add(new Tuple <string, string>(imgName, jo1["photo"]["photo_2560"].ToString()));
                        }
                        else if (jo1["photo"]["photo_1280"] != null)
                        {
                            links.Add(new Tuple <string, string>(imgName, jo1["photo"]["photo_1280"].ToString()));
                        }
                        else if (jo1["photo"]["photo_807"] != null)
                        {
                            links.Add(new Tuple <string, string>(imgName, jo1["photo"]["photo_807"].ToString()));
                        }
                        else if (jo1["photo"]["photo_604"] != null)
                        {
                            links.Add(new Tuple <string, string>(imgName, jo1["photo"]["photo_604"].ToString()));
                        }
                        else
                        {
                            links.Add(new Tuple <string, string>(imgName, jo1["photo"]["photo_130"].ToString()));
                        }
                        imgName = tImageName;
                    }
                }

                proceedCount += curCount;
                parsedCntLabel.Invoke(() => { parsedCntLabel.Text = "Спаршено: " + proceedCount + " из " + quantity; });
                parsedInfo.Invoke(() => { parsedInfo.Text = "(найдено " + links.Count + " изображений)"; });
            }
            return(links);
        }