示例#1
0
        public XmlDocument WallPostFoto(int uid, InstaFoto foto)
        {
            // парсим урл для загрузки
            var result    = GetWallUploadServer(uid);
            var uploadUrl = _network.GetDataFromXmlNode(result.SelectSingleNode("/response/upload_url"));

            //загружаем
            var uploadedPhoto = UploadFoto(uploadUrl, foto.Filename);

            //сохраняем
            result = SaveWallPhoto(uploadedPhoto);

            //парсим данные сохраненного фото
            uploadedPhoto.SavedID      = _network.GetDataFromXmlNode(result.SelectSingleNode("/response/photo/id"));
            uploadedPhoto.SavedPID     = _network.GetDataFromXmlNode(result.SelectSingleNode("/response/photo/pid"));
            uploadedPhoto.SavedOwnerID = _network.GetDataFromXmlNode(result.SelectSingleNode("/response/photo/owner_id"));

            //кодируем теги в урл-формате
            if (foto.Text.Contains("#"))
            {
                foto.Text = foto.Text.Replace("#", "%23");
            }

            //постим на стену
            _qs["message"]     = foto.Text + " " + foto.Link;
            _qs["attachments"] = uploadedPhoto.SavedID;
            return(ExecuteCommand("wall.post", _qs));
        }
        private InstaFoto GetInstaFotoFromXML(XmlDocument lastFoto)
        {
            var foto = new InstaFoto
            {
                Link                  = _network.GetDataFromXmlNode(lastFoto.SelectSingleNode("/baseprop/data/link")),
                LowResolutionUrl      = _network.GetDataFromXmlNode(lastFoto.SelectSingleNode("/baseprop/data/images/low_resolution/url")),
                StandardResolutionUrl = _network.GetDataFromXmlNode(lastFoto.SelectSingleNode("/baseprop/data/images/standard_resolution/url")),
                Text                  = _network.GetDataFromXmlNode(lastFoto.SelectSingleNode("/baseprop/data/caption/text")),
                Tags                  = _network.GetDataFromXmlNode(lastFoto.SelectSingleNode("/baseprop/data/tags")),
                Id        = _network.GetDataFromXmlNode(lastFoto.SelectSingleNode("/baseprop/data/caption/id")),
                NextMaxId = _network.GetDataFromXmlNode(lastFoto.SelectSingleNode("/baseprop/pagination/next_max_id"))
            };

            foto.NextMaxId = foto.NextMaxId.Substring(0, 18);

            SaveFotoToFile(foto);
            return(foto);
        }
 private void SaveFotoToFile(InstaFoto foto)
 {
     _logs.WriteLog("log.txt", "SaveFotoToFile");
     _logs.WriteLog("log.txt", "filename");
     _fileName = @"fotos/" + foto.Link.Replace("http://instagram.com/p/", "").Replace("/", "") + ".jpg";
     lock (_locker)
     {
         _logs.WriteLog("log.txt", "downloading");
         using (var client = new WebClient())
         {
             if (!(File.Exists(_fileName)))
             {
                 _logs.WriteLog("log.txt", "DownloadFile");
                 client.DownloadFile(foto.StandardResolutionUrl, _fileName);
             }
         }
     }
     foto.Filename = _fileName;
 }