Пример #1
0
        public string GetAccessToken(string code, out long vkId)
        {
            string requestString = "https://oauth.vk.com/access_token?" +
                                   $"client_id={clientId}&" +
                                   $"client_secret={clientSecret}&" +
                                   $"redirect_uri={redirectUri}&" +
                                   $"code={code}";
            var obj = WebRequestExtensions.GetBodyObject(requestString);

            vkId = obj.user_id;
            return(obj.access_token);
        }
Пример #2
0
        public string GetName(User user)
        {
            string requestString = "https://api.vk.com/method/users.get?" +
                                   $"user_id={user.VkId}&" +
                                   "fields=name&" +
                                   $"access_token={user.Token}&" +
                                   $"v={version}";

            var obj = WebRequestExtensions.GetBodyObject(requestString);

            return(HandleFucn(obj, new Func <dynamic>(() =>
                                                      $"{obj.response[0].first_name} {obj.response[0].last_name}")));
        }
Пример #3
0
        public List <string> GetFriends(User user)
        {
            string requestString = "https://api.vk.com/method/friends.get?" +
                                   $"user_id={user.VkId}&" +
                                   "order=random&" +
                                   "fields=name&" +
                                   "count=5&" +
                                   $"access_token={user.Token}&" +
                                   $"v={version}";

            var obj = WebRequestExtensions.GetBodyObject(requestString);

            return(HandleFucn(obj, new Func <dynamic>(() =>
                                                      new List <dynamic>(obj.response.items).Select(x => $"{x.first_name} {x.last_name}").ToList())));
        }