Пример #1
0
        //VK Api v5.0
        private static VkProfile ParseV5(JToken json)
        {
            var result = new VkProfile();

            result.Id = (long)json["id"];
            result.FirstName = (string)json["first_name"];
            result.LastName = (string)json["last_name"];

            if (json["photo"] != null) //NOTE in some methods this used instead of photo_xx
                result.Photo = (string)json["photo"];

            if (json["photo_50"] != null)
                result.Photo = (string)json["photo_50"];

            if (json["photo_100"] != null)
                result.PhotoMedium = json["photo_100"].Value<string>();

            if (json["photo_200_orig"] != null)
                result.PhotoBig = json["photo_200_orig"].Value<string>();

            if (json["photo_200"] != null)
                result.PhotoBigSquare = json["photo_200"].Value<string>();

            if (json["photo_400_orig"] != null)
                result.PhotoLarge = json["photo_400_orig"].Value<string>();

            if (json["photo_max"] != null)
                result.PhotoMaxSquare = json["photo_max"].Value<string>();

            if (json["photo_max_orig"] != null)
                result.PhotoMax = json["photo_max_orig"].Value<string>();

            if (json["online"] != null)
                result.IsOnline = (int)json["online"] == 1;

            if (json["online_mobile"] != null)
                result.IsOnlineMobile = (int)json["online"] == 1;

            if (json["last_seen"] != null)
                result.LastSeen = DateTimeExtensions.UnixTimeStampToDateTime((long)json["last_seen"]["time"]);

            if (json["sex"] != null)
            {
                result.Sex = (VkSex)(int)json["sex"];
            }

            return result;
        }
Пример #2
0
        public async Task <VkItemsResponse <VkProfile> > Get(IEnumerable <string> userIds, string fields = null, string nameCase = null)
        {
            var parameters = new Dictionary <string, string>();

            if (userIds != null)
            {
                parameters.Add("user_ids", string.Join(",", userIds));
            }

            if (!string.IsNullOrWhiteSpace(fields))
            {
                parameters.Add("fields", fields);
            }

            if (!string.IsNullOrWhiteSpace(nameCase))
            {
                parameters.Add("name_case", nameCase);
            }

            _vkontakte.SignMethod(parameters);

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

            if (response["response"] != null)
            {
                return(new VkItemsResponse <VkProfile>((from u in response["response"] select VkProfile.FromJson(u)).ToList()));
            }

            return(VkItemsResponse <VkProfile> .Empty);
        }
Пример #3
0
        internal static VkProfile FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentNullException("json");
            }

            var result = new VkProfile();

            result.Id        = (long)json["id"];
            result.FirstName = (string)json["first_name"];
            result.LastName  = (string)json["last_name"];

            if (json["photo"] != null) //NOTE in some methods this used instead of photo_xx
            {
                result.Photo = (string)json["photo"];
            }

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

            if (json["photo_100"] != null)
            {
                result.PhotoMedium = json["photo_100"].Value <string>();
            }

            if (json["photo_200_orig"] != null)
            {
                result.PhotoBig = json["photo_200_orig"].Value <string>();
            }

            if (json["photo_200"] != null)
            {
                result.PhotoBigSquare = json["photo_200"].Value <string>();
            }

            if (json["photo_400_orig"] != null)
            {
                result.PhotoLarge = json["photo_400_orig"].Value <string>();
            }

            if (json["photo_max"] != null)
            {
                result.PhotoMaxSquare = json["photo_max"].Value <string>();
            }

            if (json["photo_max_orig"] != null)
            {
                result.PhotoMax = json["photo_max_orig"].Value <string>();
            }

            if (json["online"] != null)
            {
                result.IsOnline = (int)json["online"] == 1;
            }

            if (json["online_mobile"] != null)
            {
                result.IsOnlineMobile = (int)json["online"] == 1;
            }

            if (json["last_seen"] != null)
            {
                result.LastSeen = DateTimeExtensions.UnixTimeStampToDateTime((long)json["last_seen"]["time"]);
            }

            if (json["sex"] != null)
            {
                result.Sex = (VkSex)(int)json["sex"];
            }

            return(result);
        }
Пример #4
0
        public async Task <VkItemsResponse <VkProfile> > Get(IEnumerable <string> userIds, string fields = null, string nameCase = null)
        {
            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 (userIds != null)
            {
                parameters.Add("user_ids", string.Join(",", userIds));
            }

            if (!string.IsNullOrWhiteSpace(fields))
            {
                parameters.Add("fields", fields);
            }

            if (!string.IsNullOrWhiteSpace(nameCase))
            {
                parameters.Add("name_case", nameCase);
            }

            _vkontakte.SignMethod(parameters);

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

            VkErrorProcessor.ProcessError(response);

            if (response.SelectToken("response") != null)
            {
                return(new VkItemsResponse <VkProfile>((from u in response["response"] select VkProfile.FromJson(u)).ToList()));
            }

            return(VkItemsResponse <VkProfile> .Empty);
        }