private async System.Threading.Tasks.Task RetriveUserInfo(AccessTokenData accessToken)
        {
            var client = new Facebook.FacebookClient(accessToken.AccessToken);

			dynamic result = null;
			bool failed = false;
			try
			{
				result = await client.GetTaskAsync("me?fields=id,birthday,first_name,last_name,middle_name,gender");
			}
			catch(Exception e)
			{
				failed = true;
			}
			if(failed)
			{
				MessageDialog dialog = new MessageDialog("Facebook is not responding to our authentication request. Sorry.");
				await dialog.ShowAsync();

				throw new Exception("Windows phone does not provide an exit function, so we have to crash the app.");
			}
            string fullName = string.Join(" ", new[] { result.first_name, result.middle_name, result.last_name });
            string preferredName = result.last_name;
            bool? gender = null;
            if (result.gender == "female")
            {
                gender = true;
            }
            else if (result.gender == "male")
            {
                gender = false;
            }
            DateTime birthdate = DateTime.UtcNow - TimeSpan.FromDays(365 * 30);
            if (result.birthday != null)
            {
                birthdate = DateTime.Parse(result.birthday);
            }

            var currentUser = new Facebook.Client.GraphUser(result);

            long facebookId = long.Parse(result.id);

            UserState.ActiveAccount = await Api.Do.AccountFacebook(facebookId);
            if (UserState.ActiveAccount == null)
            {
                Frame.Navigate(typeof(CreatePage), new CreatePage.AutofillInfo
                    {
                        SocialId = facebookId,
						Authenticator = Authenticator.Facebook,
                        Birthdate = birthdate,
                        FullName = fullName,
                        Gender = gender,
                        PreferredName = preferredName
                    });
            }
            else
            {
                Frame.Navigate(typeof(MainPage), UserState.CurrentId);
            }
        }
Esempio n. 2
0
        private async void OnFacebookAuthenticationFinished(AccessTokenData session)
        {
            // here the authentication succeeded callback will be received.
            // put your login logic here
            try
            {
                FacebookClient client = new FacebookClient(session.AccessToken);

                //Graph request and result
                dynamic result = await client.GetTaskAsync("me");

                //Getting current user from graph request result
                var currentUser = new Facebook.Client.GraphUser(result);

                //Do something with current user data
                var fad = new FacebookAccountData()
                {
                    SocialNetworkId = currentUser.Id,
                    Name = currentUser.Name,
                    LastName = currentUser.LastName,
                    FirstName = currentUser.FirstName,
                    Email = "",
                    Link = currentUser.Link,
                    MiddleName = currentUser.MiddleName
                };
            }
            catch (Exception ex)
            {
                //Handle exception
            }
        }
        private async void RetriveUserInfo()
        {
            var     token  = Session.ActiveSession.CurrentAccessTokenData.AccessToken;
            var     client = new Facebook.FacebookClient(token);
            dynamic result = await client.GetTaskAsync("me");

            var currentUser = new Facebook.Client.GraphUser(result);
            //this.userInfo.Text = this.BuildUserInfoDisplay(currentUser);
        }
Esempio n. 4
0
        private async System.Threading.Tasks.Task RetriveUserInfo()
        {
            profpic.ProfileId = App.FacebookId;
            var     cli    = new Facebook.FacebookClient(App.AccessToken);
            dynamic result = await cli.GetTaskAsync("me");

            var currentUser = new Facebook.Client.GraphUser(result);

            fnfb.Text = currentUser.FirstName;
            lnfb.Text = currentUser.LastName;
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the FBUser class from a GraphUser
        /// </summary>
        public FBUser(GraphUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            this.Id = user.Id;
            this.Name = user.Name;
            this.UserName = user.UserName;
            this.FirstName = user.FirstName;
            this.MiddleName = user.MiddleName;
            this.LastName = user.LastName;
            this.Birthday = user.Birthday;
            if (user.Location == null)
                this.Location = null;
            else
                this.Location = new FBLocation(user.Location);
            this.Link = user.Link;
            this.ProfilePictureUrl = user.ProfilePictureUrl;
        }
Esempio n. 6
0
        async System.Threading.Tasks.Task updateMyInfo()
        {
            try
            {
                var client = new Facebook.FacebookClient(session.AccessToken);
                dynamic result = await client.GetTaskAsync("me");
                var currentUser = new Facebook.Client.GraphUser(result);

                ADFacebookWP8Impl.myInfo(currentUser.Id, currentUser.LastName, currentUser.FirstName);
            }
            catch (Exception)
            { }
        }
Esempio n. 7
0
 void UserInfoChanged(object sender, Facebook.Client.Controls.UserInfoChangedEventArgs e)
 {
     Facebook.Client.GraphUser user = e.User;
 }
        /// <summary>
        /// Get current logged in user info
        /// </summary>
        public static void GetCurrentUser(Action<FBUser> callback)
        {
#if NETFX_CORE
            API("me", HttpMethod.GET, (result) =>
            {
                var data = (IDictionary<string, object>)result.Json;
                var me = new GraphUser(data);

                if (callback != null)
                    callback(new FBUser(me));
            });
#else
            throw new PlatformNotSupportedException("");
#endif
        }
        /// <summary>
        /// Handles the page load event
        /// </summary>
        /// <param name="sender">
        /// Sender object
        /// </param>
        /// <param name="e">
        /// Event args
        /// </param>
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            var session = SessionStorage.Load();

            if (null != session)
            {
                this.ExpiryText.Text = string.Format("Login expires on: {0}", session.Expires.ToString());

                this.ProgressText = "Fetching details from Facebook...";
                this.ProgressIsVisible = true;

                try
                {
                    var fb = new FacebookClient(session.AccessToken);

                    dynamic result = await fb.GetTaskAsync("me");
                    var user = new GraphUser(result);
                    user.ProfilePictureUrl = new Uri(string.Format("https://graph.facebook.com/{0}/picture?access_token={1}", user.Id, session.AccessToken));

                    this.CurrentUser = user;

                    await this.GetUserStatus(fb);
                }
                catch (FacebookOAuthException exception)
                {
                    MessageBox.Show("Error fetching user data: " + exception.Message);
                }

                this.ProgressText = string.Empty;
                this.ProgressIsVisible = false;
            }
        }
Esempio n. 10
0
 internal async static void OnFacebookAuthenticationFinished(AccessTokenData session)
 {
     fb = new Facebook.FacebookClient(Session.ActiveSession.CurrentAccessTokenData.AccessToken);
     result = await fb.GetTaskAsync("me");
     currentUser = new Facebook.Client.GraphUser(result);
 }
        private async System.Threading.Tasks.Task RetriveUserInfo(AccessTokenData accessToken)
        {
            var client = new Facebook.FacebookClient(accessToken.AccessToken);

            dynamic result = null;
            bool    failed = false;

            try
            {
                result = await client.GetTaskAsync("me?fields=id,birthday,first_name,last_name,middle_name,gender");
            }
            catch (Exception e)
            {
                failed = true;
            }
            if (failed)
            {
                MessageDialog dialog = new MessageDialog("Facebook is not responding to our authentication request. Sorry.");
                await dialog.ShowAsync();

                throw new Exception("Windows phone does not provide an exit function, so we have to crash the app.");
            }
            string fullName      = string.Join(" ", new[] { result.first_name, result.middle_name, result.last_name });
            string preferredName = result.last_name;
            bool?  gender        = null;

            if (result.gender == "female")
            {
                gender = true;
            }
            else if (result.gender == "male")
            {
                gender = false;
            }
            DateTime birthdate = DateTime.UtcNow - TimeSpan.FromDays(365 * 30);

            if (result.birthday != null)
            {
                birthdate = DateTime.Parse(result.birthday);
            }

            var currentUser = new Facebook.Client.GraphUser(result);

            long facebookId = long.Parse(result.id);

            UserState.ActiveAccount = await Api.Do.AccountFacebook(facebookId);

            if (UserState.ActiveAccount == null)
            {
                Frame.Navigate(typeof(CreatePage), new CreatePage.AutofillInfo
                {
                    SocialId      = facebookId,
                    Authenticator = Authenticator.Facebook,
                    Birthdate     = birthdate,
                    FullName      = fullName,
                    Gender        = gender,
                    PreferredName = preferredName
                });
            }
            else
            {
                Frame.Navigate(typeof(MainPage), UserState.CurrentId);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Get current logged in user info
        /// </summary>
        public static void GetCurrentUser(Action<FBUser> callback)
        {
            API("me", HttpMethod.GET, (result) =>
            {
                var data = (IDictionary<string, object>)result.Json;
                var me = new GraphUser(data);

                if (callback != null)
                    callback(new FBUser(me));
            });
        }