예제 #1
0
        public async Task <VkPhoto> SaveWallPhoto(string server, string photo, string hash, long userId = 0, long groupId = 0)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("server", server);
            parameters.Add("photo", photo);
            parameters.Add("hash", hash);

            if (userId != 0)
            {
                parameters.Add("user_id", userId.ToString());
            }

            if (groupId != 0)
            {
                parameters.Add("group_id", groupId.ToString());
            }

            parameters.Add("access_token", _vkontakte.AccessToken.Token);

            var response = await VkRequest.GetAsync(VkConst.MethodBase + "photos.saveWallPhoto", parameters);

            if (response["response"] != null)
            {
                return(VkPhoto.FromJson(response["response"].First));
            }

            return(null);
        }
예제 #2
0
 public VkPhotoAttachment(VkPhoto photo)
 {
     this.Id = photo.Pid;
     this.OwnerId = photo.OwnerId;
     this.Source = photo.Src;
     this.SourceBig = photo.SrcBig;
     this.SourceSmall = photo.SrcSmall;
     this.Date = photo.Created;
 }
예제 #3
0
        public static VkPhoto FromJson(JToken json)
        {
            if (json == null)
                throw new ArgumentNullException("json");

            var result = new VkPhoto();
            result.Id = (string)json["id"];
            result.Pid = (long)json["pid"];
            result.Aid = (int)json["aid"];
            result.OwnerId = (long)json["owner_id"];
            result.Src = (string)json["src"];
            result.SrcBig = (string)json["src_big"];
            result.SrcSmall = (string)json["src_small"];
            result.Width = (int)json["width"];
            result.Height = (int)json["height"];
            result.Text = (string)json["text"];
            result.Created = DateTimeExtensions.UnixTimeStampToDateTime((long)json["created"]);

            return result;
        }
예제 #4
0
        public static VkPhoto FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentNullException("json");
            }

            var result = new VkPhoto();

            result.Id       = (string)json["id"];
            result.Pid      = (long)json["pid"];
            result.Aid      = (int)json["aid"];
            result.OwnerId  = (long)json["owner_id"];
            result.Src      = (string)json["src"];
            result.SrcBig   = (string)json["src_big"];
            result.SrcSmall = (string)json["src_small"];
            result.Width    = (int)json["width"];
            result.Height   = (int)json["height"];
            result.Text     = (string)json["text"];
            result.Created  = DateTimeExtensions.UnixTimeStampToDateTime((long)json["created"]);

            return(result);
        }
예제 #5
0
        public async Task <VkPhoto> SaveMessagePhoto(string server, string photo, string hash)
        {
            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>();

            parameters.Add("server", server);
            parameters.Add("photo", photo);
            parameters.Add("hash", hash);

            _vkontakte.SignMethod(parameters);

            var response = await VkRequest.GetAsync(VkConst.MethodBase + "photos.saveMessagesPhoto", parameters);

            if (response["response"] != null)
            {
                return(VkPhoto.FromJson(response["response"].First));
            }

            return(null);
        }
예제 #6
0
        public async Task <VkPhoto> SaveWallPhoto(string server, string photo, string hash, long userId = 0, long groupId = 0)
        {
            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>();

            parameters.Add("server", server);
            parameters.Add("photo", photo);
            parameters.Add("hash", hash);

            if (userId != 0)
            {
                parameters.Add("user_id", userId.ToString());
            }

            if (groupId != 0)
            {
                parameters.Add("group_id", groupId.ToString());
            }

            parameters.Add("access_token", _vkontakte.AccessToken.Token);

            var response = await new VkRequest(new Uri(VkConst.MethodBase + "photos.saveWallPhoto"), parameters).Execute();

            VkErrorProcessor.ProcessError(response);

            if (response["response"] != null)
            {
                return(VkPhoto.FromJson(response["response"].First));
            }

            return(null);
        }
예제 #7
0
        public static VkPhoto FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentNullException("json");
            }

            var result = new VkPhoto();

            if (json["id"] != null)
            {
                result.Id = (long)json["id"];
            }

            if (json["album_id"] != null)
            {
                result.AlbumId = (long)json["album_id"];
            }

            if (json["owner_id"] != null)
            {
                result.OwnerId = (long)json["owner_id"];
            }

            if (json["photo_75"] != null)
            {
                result.Photo75 = (string)json["photo_75"];
            }

            if (json["photo_130"] != null)
            {
                result.Photo130 = (string)json["photo_130"];
            }

            if (json["photo_604"] != null)
            {
                result.Photo604 = (string)json["photo_604"];
            }

            if (json["photo_807"] != null)
            {
                result.Photo807 = (string)json["photo_807"];
            }

            if (json["photo_1280"] != null)
            {
                result.Photo1280 = (string)json["photo_1280"];
            }

            if (json["photo_2560"] != null)
            {
                result.Photo2560 = (string)json["photo_2560"];
            }

            if (json["width"] != null)
            {
                result.Width = (int)json["width"];
            }

            if (json["height"] != null)
            {
                result.Height = (int)json["height"];
            }

            if (json["text"] != null)
            {
                result.Text = (string)json["text"];
            }

            if (json["date"] != null)
            {
                result.Created = DateTimeExtensions.UnixTimeStampToDateTime((long)json["date"]);
            }

            return(result);
        }