public IProfile getProfileById(string id) { long id_ = Int64.Parse(id); if (id_ > 0) { foreach (NFProfile profile in profiles) { if (profile.id.Equals(id)) return profile; } } else { id_ *= -1; foreach (NFGroup group in groups) { if (group.id.Equals(id_.ToString())) return group; } } WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; String answer = wc.DownloadString("https://api.vk.com/method/users.get?user_ids=" + id+"&fields=photo_max"); JObject obj = JObject.Parse(answer); NFProfile profile_ = new NFProfile(); profile_.id = id; profile_.first_name = obj["response"].First["first_name"].ToString(); profile_.last_name = obj["response"].First["last_name"].ToString(); profile_.photo_url = obj["response"].First["photo_max"].ToString(); return profile_; }
public static Newsfeed getNewsfeed(SocAccount sa) { WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; String answer = wc.DownloadString("https://api.vk.com/method/newsfeed.get?access_token=" + sa.TOKEN + "&max_photos=100"); JObject obj = JObject.Parse(answer); JToken jtoken = obj["response"]["items"].First; Newsfeed newsfeed = new Newsfeed(); //newsfeed do { switch (jtoken["type"].ToString()) { case "wall_photo": WallPhoto wallphoto = new WallPhoto(); wallphoto.attach = getPhotoAttachments(jtoken); wallphoto.date = (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(int.Parse(jtoken["date"].ToString())); wallphoto.idFrom = jtoken["source_id"].ToString(); newsfeed.feed.Add(wallphoto); break; case "post": Post post = new Post(); if (jtoken["attachments"]!=null) post.attach = getAttachments(jtoken); post.date = (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(int.Parse(jtoken["date"].ToString())); post.idFrom = jtoken["source_id"].ToString(); post.text = jtoken["text"].ToString(); post.id = jtoken["post_id"].ToString(); newsfeed.feed.Add(post); break; case "photo": Photo photo = new Photo(); photo.idFrom = jtoken["source_id"].ToString(); photo.date = (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(int.Parse(jtoken["date"].ToString())); photo.attach = getPhotoAttachments(jtoken); newsfeed.feed.Add(photo); break; case "friend": Friend friend = new Friend(); friend.date = (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(int.Parse(jtoken["date"].ToString())); friend.attach = getFriendAttachments(jtoken); friend.idFrom = jtoken["source_id"].ToString(); newsfeed.feed.Add(friend); break; default: break; } jtoken = jtoken.Next; } while (jtoken != null); #region profiles jtoken = obj["response"]["profiles"].First; do { NFProfile profile = new NFProfile(); profile.id = jtoken["uid"].ToString(); profile.first_name = jtoken["first_name"].ToString(); profile.last_name = jtoken["last_name"].ToString(); profile.photo_url = jtoken["photo"].ToString(); newsfeed.profiles.Add(profile); jtoken = jtoken.Next; } while (jtoken != null); #endregion #region groups jtoken = obj["response"]["groups"].First; do { NFGroup group = new NFGroup(); group.id = jtoken["gid"].ToString(); group.name = jtoken["name"].ToString(); group.screen_name = jtoken["screen_name"].ToString(); group.photo_url = jtoken["photo"].ToString(); newsfeed.groups.Add(group); jtoken = jtoken.Next; } while (jtoken != null); #endregion return newsfeed; }