【问题标题】:Authentication with Facebook by using Xamarin.Auth使用 Xamarin.Auth 通过 Facebook 进行身份验证
【发布时间】:2016-02-02 13:24:38
【问题描述】:

我在我的应用程序(android/iOS)中使用 Xamarin.Auth 登录 facebook,一切顺利,但成功登录后,facebook 个人资料正在打开,而不是返回到我的应用程序。我想在不显示 facebook 个人资料的情况下重定向到我的应用主页。我正在关注这个tutorial 并没有取得任何成功。我想我没有给出我的应用程序的正确网址。请给我建议。 提前感谢您的帮助。

这是我的 loginPageRenderer 代码:

[assembly: ExportRenderer (typeof (FBLoginPage), typeof (LoginPageRendrerr))]
 namespace FFirst_app.Droid
 {
public class LoginPageRendrerr : PageRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged(e);

        // this is a ViewGroup - so should be able to load an AXML file and FindView<>
        var activity = this.Context as Activity;

        var auth = new OAuth2Authenticator (
            clientId: "7b745e26dbb64e1a3a3bf6bfd33165bc", // your OAuth2 client id
            scope: "basic", // the scopes for the particular API you're accessing, delimited by "+" symbols
            authorizeUrl: new Uri("https://apps.facebook.com/myappppppp"),//("https://api.instagram.com/oauth/authorize/"), // the auth URL for the service
            redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html")); // the redirect URL for the service

        auth.Completed += (sender, eventArgs) => {
            if (eventArgs.IsAuthenticated) 
            {
                App.SuccessfulLoginAction.Invoke();

                // Use eventArgs.Account to do wonderful things
                App.SaveToken(eventArgs.Account.Properties["access_token"]);

                string sessionToken = App.Token;   //  /* Authenticate the user with Facebook and fetch a session token */;
                DateTime expiration =  DateTime.Today;  ///* The expiration time for the session token */;
                string facebookId = Constants.FBAppId;
                 ParseFacebookUtils.LogInAsync (facebookId, sessionToken, expiration);

            } else {
                // The user cancelled
            }



        };

        activity.StartActivity (auth.GetUI(activity));
    }
}

 }

【问题讨论】:

    标签: xamarin facebook-login xamarin.auth


    【解决方案1】:

    我找到了答案,我的 URL 有误,现在当我将“authorizeUrl:”更改为“http://www.facebook.com/connect/login_success.html”后它可以正常工作,并且这个 URl 也按原样设置在 FB App 上。所以现在我的代码可以正常工作.

    【讨论】:

      【解决方案2】:

      Xamarin.Auth Getting Started 页面上,提到在 iOS 上关闭 UI 由您决定:

      auth.Completed += (sender, eventArgs) => {
      
          // We presented the UI, so it's up to us to dimiss it on iOS.
          **> DismissViewController (true, null); <**
      
          if (eventArgs.IsAuthenticated) {
              // Use eventArgs.Account to do wonderful things
          } else {
              // The user cancelled
          }
      };
      

      【讨论】:

        猜你喜欢
        • 2014-09-11
        • 2014-06-13
        • 2012-04-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-28
        • 2015-11-08
        • 1970-01-01
        • 2014-10-18
        相关资源
        最近更新 更多