예제 #1
0
        async Task <List <long> > IVkService.GetTimePostAsync(string access_token, string count, string offset, string owner_id, string domain)
        {
            var filter   = "postponed";
            var listDate = new List <long>(100);

            try
            {
                var url = "https://api.vk.com/method/wall.get";

                var values = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("access_token", access_token),
                    new KeyValuePair <string, string>("offset", offset),
                    new KeyValuePair <string, string>("count", count),
                    new KeyValuePair <string, string>("filter", filter),
                    new KeyValuePair <string, string>("v", VERSION)
                };

                if (!string.IsNullOrWhiteSpace(owner_id.Trim('-')))
                {
                    values.Add(new KeyValuePair <string, string>("owner_id", owner_id));
                }
                else
                {
                    values.Add(new KeyValuePair <string, string>("domain", domain));
                }

                using (var formContent = new FormUrlEncodedContent(values))
                {
                    var result = string.Empty;

                    try
                    {
                        using (var httpClient = new HttpClient())
                            using (HttpResponseMessage response = await httpClient.PostAsync(url, formContent))
                                using (HttpContent content = response.Content)
                                {
                                    result = await content.ReadAsStringAsync();
                                }
                    }
                    catch (Exception ex)
                    {
                        await _telegramService.SendMessageExceptionAsync(ex);
                    }

                    if (!result.Contains("error"))
                    {
                        var response = _jsonService.JsonConvertDeserializeObjectWithNull <WallGetResponse>(result);
                        foreach (var date in response.Response.Items.Select(it => it.Date))
                        {
                            if (date != 0)
                            {
                                listDate.Add(date);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await _telegramService.SendMessageExceptionAsync(ex);
            }

            return(listDate);
        }