示例#1
0
        public async Task <IUser> GetAsync(UInt32 userId)
        {
            var requestUrl     = $"https://api.vk.com/method/users.get?user_ids={userId}&fields=photo_100&v=5.42&access_token={PrivateData.VkAppServiceToken}";
            var stringResponse = await Client.GetAsync(requestUrl).ConfigureAwait(false);

            var objectResponse = JsonObject.Parse(stringResponse);

            if (!objectResponse.ContainsKey("response") || (objectResponse["response"].ValueType != JsonValueType.Array))
            {
                throw new VkRequestException(objectResponse);
            }

            var items = new List <IUser>();

            foreach (var item in objectResponse["response"].GetArray())
            {
                items.Add(VkUser.Create(item.GetObject()));
            }
            return(items[0]);
        }
示例#2
0
        public static IUser Create(JsonObject value)
        {
            var instance = new VkUser();

            if (value.ContainsKey("id"))
            {
                instance.Id = (UInt32)value["id"].GetNumber();
            }
            if (value.ContainsKey("first_name"))
            {
                instance.FirstName = value["first_name"].GetString();
            }
            if (value.ContainsKey("last_name"))
            {
                instance.LastName = value["last_name"].GetString();
            }
            if (value.ContainsKey("photo_100"))
            {
                instance.Photo = new Uri(value["photo_100"].GetString(), UriKind.Absolute);
            }
            return(instance);
        }