public static new VkWallPostAttachment FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } var result = new VkWallPostAttachment(); result.Id = (long)json["id"]; if (json["owner_id"] != null) { result.OwnerId = (long)json["owner_id"]; } if (json["from_id"] != null) { result.FromId = (long)json["from_id"]; } if (json["to_id"] != null) { result.ToId = (long)json["to_id"]; } if (json["date"] != null) { result.Date = DateTimeExtensions.UnixTimeStampToDateTime(json["date"].Value <long>()); } if (json["post_type"] != null) { result.PostType = (string)json["post_type"]; } if (json["text"] != null) { result.Text = (string)json["text"]; } if (json["copy_history"] != null) { result.CopyHistory = new List <VkWallEntry>(); foreach (var p in json["copy_history"]) { try { var post = VkWallEntry.FromJson(p); if (post != null) { result.CopyHistory.Add(post); } } catch (Exception ex) { Debug.WriteLine(ex); } } } if (json["can_delete"] != null) { result.CanDelete = (int)json["can_delete"] == 1; } return(result); }
public async Task <VkItemsResponse <VkWallEntry> > GetPosts(int count = 0, int offset = 0, bool extended = true) { var parameters = new Dictionary <string, string>(); if (count > 0) { parameters.Add("count", count.ToString()); } if (offset > 0) { parameters.Add("offset", offset.ToString()); } if (extended) { parameters.Add("extended", "1"); } _vkontakte.SignMethod(parameters); var response = await VkRequest.GetAsync(VkConst.MethodBase + "fave.getPosts", parameters); if (response.SelectToken("response.items") != null) { var result = new VkItemsResponse <VkWallEntry>((from n in response["response"]["items"] select VkWallEntry.FromJson(n)).ToList()); if (response["response"]["profiles"] != null) { var users = (from n in response["response"]["profiles"] select VkProfile.FromJson(n)).ToList(); foreach (var entry in result.Items) { entry.Author = users.FirstOrDefault(u => u.Id == entry.SourceId); } } if (response["response"]["groups"] != null) { var groups = (from n in response["response"]["groups"] select VkGroup.FromJson(n)).ToList(); foreach (var entry in result.Items.Where(e => e.Author == null)) { entry.Author = groups.FirstOrDefault(g => g.Id == Math.Abs(entry.SourceId)); } } return(result); } return(null); }
public async Task <VkItemsResponse <VkWallEntry> > GetPosts(int count = 0, int offset = 0, bool extended = true) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (count > 0) { parameters.Add("count", count.ToString()); } if (offset > 0) { parameters.Add("offset", offset.ToString()); } if (extended) { parameters.Add("extended", "1"); } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "fave.getPosts"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { var result = new VkItemsResponse <VkWallEntry>((from n in response["response"]["items"] select VkWallEntry.FromJson(n)).ToList()); if (response["response"]["profiles"] != null) { var users = (from n in response["response"]["profiles"] select VkProfile.FromJson(n)).ToList(); foreach (var entry in result.Items) { entry.Author = users.FirstOrDefault(u => u.Id == entry.SourceId); } } if (response["response"]["groups"] != null) { var groups = (from n in response["response"]["groups"] select VkGroup.FromJson(n)).ToList(); foreach (var entry in result.Items.Where(e => e.Author == null)) { entry.Author = groups.FirstOrDefault(g => g.Id == Math.Abs(entry.SourceId)); } } return(result); } return(null); }