Beispiel #1
0
        public async Task <LoginProviderViewModel> GetLoginProviderAsync(string accessToken)
        {
            try
            {
                var user = await _facebookClient.GetAsync <dynamic>(accessToken, "me", "fields=email,name");

                var id    = (string)user.id;
                var email = (string)user.email;
                if (string.IsNullOrEmpty(email))
                {
                    email = $"{id}@facebook.com";
                }
                return(new LoginProviderViewModel()
                {
                    Email = email,
                    ProviderId = id,
                    Name = (string)user.name,
                    Provider = Core.Entities.AccountProviderNames.Facebook,
                    AccessToken = accessToken,
                    Image = GetAvatarUrl((string)user.id),
                });
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        public async Task <Account> GetAccountAsync(string accessToken)
        {
            var result = await _facebookClient.GetAsync <dynamic>(
                accessToken, "me", "fields=id,email,name,first_name,last_name,gender,locale");

            if (result == null)
            {
                return(new Account());
            }

            var account = new Account
            {
                Id        = result.id,
                Email     = result.email,
                Name      = result.name,
                UserName  = result.name,
                FirstName = result.first_name,
                LastName  = result.last_name,
                Locale    = result.locale,
                Gender    = result.gender,
                Likes     = 0
            };

            return(account);
        }
        public async Task <List <Post> > GetPostAsync(string accessToken, int limit = 10)
        {
            var result = await _facebookClient.GetAsync <dynamic>(accessToken, "me", "fields=posts.since(" + DateTime.Now.ToString("ddMMMMyyyy") + "){id,message}");

            if (result == null)
            {
                return(new List <Post>());
            }
            var data      = Convert.ToString(result.posts.data);
            var jsonArray = JsonConvert.DeserializeObject <List <Post> >(data);

            return(jsonArray);
        }
Beispiel #4
0
        public async Task <FacebookAccount> GetAccountAsync(string accessToken)
        {
            var response = await _facebookClient.GetAsync <dynamic>(
                accessToken, "me", "fields=id,name,first_name,last_name");

            if (response == null)
            {
                throw new Exception("FacebookAccount not found. ");
            }

            FacebookAccount facebookAccount = _modelMapper.GetFacebookAccount(response);

            return(facebookAccount);
        }
Beispiel #5
0
        public async Task <string> GetAccountAsync(string accessToken)
        {
            var result = await _facebookClient.GetAsync(Callback,
                                                        accessToken, "223644934866041/feed", "");

            return(result);
        }
Beispiel #6
0
        public async Task <Account> GetAccountAsync(string accessToken)
        {
            var result = await _facebookClient.GetAsync <dynamic>(
                accessToken, "me", "fields=id,name,email,first_name,last_name,age_range,birthday,gender,locale,location");

            if (result == null)
            {
                return(new Account());
            }

            var account = new Account
            {
                Id         = result.id,
                Email      = result.email,
                Name       = result.name,
                UserName   = result.username,
                FirstName  = result.first_name,
                LastName   = result.last_name,
                Locale     = result.locale,
                Gender     = result.gender,
                PictureUrl = "https://graph.facebook.com/" + result.id + "/picture?type=large"
            };

            return(account);
        }
Beispiel #7
0
        /// <summary>
        /// Getrequest for posts
        /// </summary>
        /// <returns>A list of dynamic post-responses</returns>
        /// <param name="accessToken">Access token.</param>
        /// <param name="endpoint">Endpoint.</param>
        /// <param name="args">Arguments.</param>
        public async Task <List <Post> > GetPostsAsync(string accessToken, string endpoint, string args)
        {
            var response = await _facebookClient.GetAsync <dynamic>(
                accessToken, endpoint, "posts", args);

            var posts = _dataHandler.PopulatePosts(response);

            if (response.paging.next != null)
            {
                NextPostId = response.paging.cursors.after;
            }
            else
            {
                NextPostId = "";
            }

            return(posts);
        }
Beispiel #8
0
        public async Task <Community> GetCommunityAsync(string accessToken)
        {
            Community result = await _facebookClient.GetAsync <Community>(
                accessToken, "community", "fields=id,name,privacy");

            if (result == null)
            {
                return(new Community());
            }

            var communityObj = new Community
            {
                Id      = result.Id,
                Name    = result.Name,
                Privacy = result.Privacy
            };


            return(communityObj);
        }
        public async Task <AccountDto> GetAccountAsync(string accessToken)
        {
            var result = await facebookClient.GetAsync <dynamic>(
                accessToken, "me", "fields=id,name,email,first_name,last_name,age_range,birthday,gender,locale");

            if (result == null)
            {
                return(new AccountDto());
            }

            var account = new AccountDto
            {
                Id        = result.id,
                Email     = result.email,
                Name      = result.name,
                UserName  = result.username,
                FirstName = result.first_name,
                LastName  = result.last_name,
                Locale    = result.locale
            };

            return(account);
        }
        public async Task <Account> GetAccountAsync(string accessToken)
        {
            var result = await _facebookClient.GetAsync <dynamic>(accessToken, "me", "fields=id,name,email,first_name,last_name");

            if (result == null)
            {
                return(new Account());
            }

            return(new Account()
            {
                Id = result.id,
                Email = result.email
            });
        }
        public async Task <FeedPostsDto> GetPostsAsync(int count)
        {
            if (count > 100)
            {
                count = 100;
            }

            var posts = await _facebookClient.GetAsync <FeedPosts>(_facebookSettings.AccessToken, "KNKredek/posts",
                                                                   $"fields=full_picture,link,message&limit={count}").ConfigureAwait(false);

            if (posts == null)
            {
                return(null);
            }

            var result = Mapper.Map <FeedPostsDto>(posts);

            return(result);
        }
Beispiel #12
0
        async Task <XmlDocument> GetAsync(string endPoint, string args)
        {
            var result = await facebookClient.GetAsync(UpdateStatus, accessToken, endPoint, args);

            string res;

            if (result == null)
            {
                res = "{}";
            }
            else
            {
                res = result;
            }
            res = CleanXml("{page:," + res.Substring(1));
            XmlDocument xmlDocument = JsonConvert.DeserializeXmlNode(res);

            return(xmlDocument);
        }
Beispiel #13
0
        public async Task <Account> GetAccountAsync(string accessToken)
        {
            var result = await _facebookClient.GetAsync <dynamic>(accessToken, "me", "fields=id,fan_count,unread_notif_count,rating_count,unread_message_count");

            if (result == null)
            {
                return(new Account());
            }

            var account = new Account
            {
                Id                  = result.id,
                FanCount            = result.fan_count,
                UnreadNotifications = result.unread_notif_count,
                UnreadMessenges     = result.unread_message_count,
                NumberOfRatings     = result.rating_count
            };

            return(account);
        }
Beispiel #14
0
        public async Task <FeedPostsDto> GetPostsAsync(int count)
        {
            FeedPostsDto result = new FeedPostsDto()
            {
                Posts = new List <FeedPostDto>()
            };

            try
            {
                var posts = await _facebookClient.GetAsync <FeedPosts>(_facebookSettings.AccessToken, Endpoint,
                                                                       $"fields=full_picture,permalink_url,created_time,message&limit={count}").ConfigureAwait(false);

                return(posts is null ? result : _mapper.Map <FeedPostsDto>(posts));
            }
            catch (System.Exception e)
            {
            }

            return(result);
        }
Beispiel #15
0
        public async Task <Account> GetAccountAsync(string accessToken)
        {
            var result = await _facebookClient.GetAsync <dynamic>(
                accessToken, "me", "fields=id,birthday,name,first_name,last_name,email");

            if (result == null)
            {
                return(new Account());
            }

            var account = new Account
            {
                Id        = result.id,
                Birthday  = result.birthday,
                Name      = result.name,
                FirstName = result.first_name,
                LastName  = result.last_name,
                Email     = result.email
            };

            return(account);
        }
Beispiel #16
0
        public async Task <FBAccount> GetAccountAsync(string accessToken)
        {
            var account = new FBAccount();

            try
            {
                //var result = await _facebookClient.GetAsync<dynamic>(accessToken, "me", "fields=id,name,email,first_name,last_name,age_range,birthday,gender,locale,picture");


                var result = await _facebookClient.GetAsync <FBAccount>(
                    accessToken, "me", "fields=id,name,email,first_name,last_name,age_range,birthday,gender,locale,picture");

                if (result == null)
                {
                    return(new FBAccount());
                }

                account = result;

                //account = new FBAccount
                //{
                //    Id = result.id,
                //    Email = result.email,
                //    Name = result.name,
                //    UserName = result.username,
                //    FirstName = result.first_name,
                //    LastName = result.last_name,
                //    Locale = result.locale,
                //    //Picture = result.picture
                //};
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


            return(account);
        }
Beispiel #17
0
        public async Task <User> GetUserAsync(string accessToken)
        {
            var result = await _facebookClient.GetAsync <dynamic>(
                accessToken, "me", "fields=id,name,email,location,picture");

            if (result == null)
            {
                return(new User());
            }

            var user = new User()
            {
                Id      = result.id.ToString(),
                Email   = result.email.ToString(),
                Name    = result.name.ToString(),
                Picture = result.picture["url"].ToString(),
                Address = result.location["name"].ToString(),
                isAdmin = false
            };

            return(user);
        }
Beispiel #18
0
        public async Task <Maybe <FacebookUser> > GetUserAsync(string accessToken)
        {
            var user = await _facebookClient.GetAsync <dynamic>(
                "me", accessToken, "fields=id,name,email,first_name,last_name,age_range,birthday,gender,locale");

            if (user == null)
            {
                return(new Maybe <FacebookUser>());
            }

            var facebookUser = new FacebookUser
            {
                Id          = user.id,
                Email       = user.email,
                Name        = user.name,
                UserName    = user.username,
                FirstName   = user.first_name,
                LastName    = user.last_name,
                PublicToken = accessToken,
                Locale      = user.locale
            };

            return(facebookUser);
        }
 public async Task <StreamInfo> GetLiveStreamByIdAsync(string accessToken, string streamId)
 {
     return(await _facebookClient.GetAsync <StreamInfo>(accessToken, streamId, "fields=ingest_streams"));
 }