Inheritance: System.EventArgs
        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || this.Element == null)
            {
                return;
            }

            loginButton = new LoginButton()
            {
                LoginBehavior = LoginBehavior.Native,
            };

            loginButton.Completed += (sender, args) => {
                FacebookButton facebookButton = (FacebookButton)e.NewElement;
                FacebookEventArgs fbArgs = new FacebookEventArgs();

                if (args.Result.Token != null)
                {
                    fbArgs.UserId = args.Result.Token.UserID;
                    fbArgs.AccessToken = args.Result.Token.TokenString;
                    fbArgs.TokenExpiration = args.Result.Token.ExpirationDate.ToDateTime();
                }

                facebookButton.Login(facebookButton, fbArgs);
            };

            SetNativeControl(loginButton);
        }
Ejemplo n.º 2
0
        private async void LoginWithFacebook(object sender, FacebookEventArgs e)
        {
            /*
                If you successfully login to facebook, you must got the three parameters that login return to the app.
                Handle whatever credetianls storage here with the data you have recovered. If you are using Parse Login with Facebook
                you may use DependencyService to access your service and pass the parameters you have recovered.
                Example:
            */
            //var success = await DependencyService.Get<IParse>().LoginWithFacebook(e.UserId, e.AccessToken, e.TokenExpiration);

            bool success = (!string.IsNullOrEmpty(e.UserId) && 
                            !string.IsNullOrEmpty(e.AccessToken) && 
                            e.TokenExpiration != null);

            if (success)
            {
                var message = string.Format("You have succesfully access to your facebook account. Data returned:\n\nUserId: {0}\n\nAccess Token: {1}\n\nExpiration Date: {2}", 
                    e.UserId, e.AccessToken, e.TokenExpiration);
                await DisplayAlert("Success", message, "Ok");
            }
            else
            {
                await DisplayAlert(
                    "Error",
                    "There was an error trying to login to facebook",
                    "Ok"
                );
            }
            DependencyService.Get<ITools>().LogoutFromFacebook();
        }
Ejemplo n.º 3
0
 public void Login(object sender, FacebookEventArgs args)
 {
     if (OnLogin != null)
         OnLogin(sender, args);
 }