public static VkPhoto FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } VkPhoto vkPhoto = new VkPhoto(); if (json["pid"] != null) { vkPhoto.PhotoId = Math.Abs(json["pid"].Value <long>()); } if (json["aid"] != null) { vkPhoto.AlbumId = Math.Abs(json["aid"].Value <long>()); } if (json["owner_id"] != null) { vkPhoto.OwnerId = Math.Abs(json["owner_id"].Value <long>()); } if (json["width"] != null) { vkPhoto.Width = Math.Abs(json["width"].Value <long>()); } if (json["height"] != null) { vkPhoto.Height = Math.Abs(json["height"].Value <long>()); } vkPhoto.Text = json["text"].Value <string>(); if (json["src"] != null) { vkPhoto.ThumbSrcNormal = new Uri(json["src"].Value <string>()); } if (json["src_big"] != null) { vkPhoto.ThumbSrcBig = new Uri(json["src_big"].Value <string>()); } if (json["src_small"] != null) { vkPhoto.ThumbSrcSmall = new Uri(json["src_small"].Value <string>()); } if (json["src_xbig"] != null) { vkPhoto.ThumbSrcXBig = new Uri(json["src_xbig"].Value <string>()); } return(vkPhoto); }
public async Task <IEnumerable <VkPhoto> > Get(string oid, string aid, IList <string> pids = null, int rev = 0, int extended = 0, string feed_type = null, int feed = 0) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (pids != null) { dictionary.Add("pids", string.Join(",", pids)); } if (!string.IsNullOrEmpty(oid)) { dictionary.Add("oid", oid); } if (!string.IsNullOrEmpty(aid)) { dictionary.Add("aid", aid); } dictionary.Add("rev", rev.ToString()); dictionary.Add("extended", extended.ToString()); if (!string.IsNullOrEmpty(feed_type)) { dictionary.Add("feed_type", feed_type); } if (feed != 0) { dictionary.Add("feed", feed.ToString()); } JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/photos.get"), dictionary, "GET").Execute(); IEnumerable <VkPhoto> result; if (VkErrorProcessor.ProcessError(jObject)) { result = null; } else { if (jObject["response"].HasValues) { result = Enumerable.Select <JToken, VkPhoto>(Enumerable.Skip <JToken>(jObject["response"], 1), (JToken a) => VkPhoto.FromJson(a)); //result = Enumerable.Select<JToken, VkPhotoAlbum>(Enumerable.Where<JToken>(jObject["response"], (JToken v) => v.HasValues), (JToken v) => VkPhotoAlbum.FromJson(v)); } else { result = null; } } return(result); }