예제 #1
0
        public static VkWallEntry FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }
            VkWallEntry vkWallEntry = new VkWallEntry();

            vkWallEntry.Id = json["id"].Value <double>();
            if (json["attachments"] != null)
            {
                vkWallEntry.Attachments = new List <VkAttachment>();
                using (IEnumerator <JToken> enumerator = json["attachments"].AsEnumerable().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        JToken current = enumerator.Current;
                        string text;
                        if ((text = current["type"].Value <string>()) != null && text == "audio")
                        {
                            vkWallEntry.Attachments.Add(VkAudioAttachment.FromJson(current["audio"]));
                        }
                    }
                }
            }
            return(vkWallEntry);
        }
예제 #2
0
        public async Task <VkWallResult> Get(string ownerId, string filter, int count = 0, int offset = 0)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(ownerId))
            {
                dictionary.Add("owner_id", ownerId);
            }
            if (!string.IsNullOrEmpty(filter))
            {
                dictionary.Add("filter", filter);
            }
            if (count > 0)
            {
                dictionary.Add("count", count.ToString());
            }
            if (offset > 0)
            {
                dictionary.Add("offset", offset.ToString());
            }
            dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token);
            JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/wall.get"), dictionary, "GET").Execute();

            VkErrorProcessor.ProcessError(jObject);
            VkWallResult result;

            if (jObject["response"] != null)
            {
                VkWallResult vkWallResult = new VkWallResult();
                vkWallResult.Count = jObject["response"].First.Value <int>();
                vkWallResult.Posts = Enumerable.Select <JToken, VkWallEntry>(Enumerable.Where <JToken>(jObject["response"], (JToken p) => p.HasValues), (JToken p) => VkWallEntry.FromJson(p));
                result             = vkWallResult;
            }
            else
            {
                result = null;
            }
            return(result);
        }