Good time of day.
Returns the message history for the specified user or group conversation.
Returns an array of message objects - personal messages in the specified dialog with the user or group conversation. Each message object contains a set of fields, a description of which is available here.
using System.Xml.Linq; XDocument doc; int m=0; int k=0; WebClient src_client = new WebClient(); Directory.CreateDirectory("img/"); doc = XDocument.Load("https://api.vk.com/method/messages.getHistory.xml?uid=123456&offset=" + m + "&count=200&access_token=" + token); while (true) { doc = XDocument.Load("https://api.vk.com/method/messages.getHistory.xml?uid=12345&offset=" + m + "&count=200&access_token=" + token);// xml foreach (XElement el in doc.Root.Elements())// { // if (el.Name.ToString() == "message") { foreach (XElement el_msg in el.Elements())// message { // if (el_msg.Name == "attachment") { foreach (XElement el_attch in el_msg.Elements()) { // , , if (el_attch.Name == "photo") { foreach (XElement el_photo in el_attch.Elements()) { // if (el_photo.Name == "src_xbig") { // img/ src_client.DownloadFile(el_photo.Value, "img/img" + k + ".jpg"); k++; } } } } } } } } // count m += 200; } while (true) { var doc = XDocument.Load("https://api.vk.com/method/messages.getHistory.xml?uid=12345&offset=" + m + "&count=" + n + "&access_token=" + token);// xml var photoElements= doc.Root.Elements("message") .SelectMany(el => el.Elements("attachment") .SelectMany(el_msg => el_msg.Elements("photo") .SelectMany(elAttch => elAttch.Elements("src_xbig")))); foreach (var el_photo in photoElements) { // img/ src_client.DownloadFile(el_photo.Value, "img/img" + k + ".jpg"); k++; } // count m += n; } using System.Xml.XPath; // XPathDocument document_x = new XPathDocument("https://api.vk.com/method/messages.getHistory.xml?uid=12345&offset=" + m + "&count=200&access_token=" + token); XPathNavigator navigator = document_x.CreateNavigator(); // string str_exp = "//message//attachment//photo//src_big"; XPathExpression expres = XPathExpression.Compile(str_exp); XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); expres.SetContext(manager); XPathNodeIterator nodes = navigator.Select(expres); while (nodes.MoveNext())// src_client.DownloadFile(nodes.Current.ToString(), "img/imj" + k + ".jpg");// Source: https://habr.com/ru/post/173421/
All Articles