Inheritance: Java.Lang.Object, IFacebookCallback
コード例 #1
0
ファイル: Facebook.cs プロジェクト: kentcb/SimpleAuth
        public static async void Login(WebAuthenticator authenticator)
        {
            var fbAuthenticator = authenticator as FacebookAuthenticator;

            var currentActivity = activityLifecycleManager.CurrentActivity;

            FacebookSdk.SdkInitialize(currentActivity);

            callbackManager = CallbackManagerFactory.Create();
            var loginManager = LoginManager.Instance;
            var fbHandler    = new FbCallbackHandler();

            loginManager.RegisterCallback(callbackManager, fbHandler);

            fbHandler.Reset();

            if (RequestPublishPermissions)
            {
                loginManager.LogInWithPublishPermissions(currentActivity, fbAuthenticator.Scope);
            }
            else
            {
                loginManager.LogInWithReadPermissions(currentActivity, fbAuthenticator.Scope);
            }

            LoginResult result = null;

            try
            {
                result = await fbHandler.Task;
            }
            catch (Exception ex)
            {
                fbAuthenticator.OnError(ex.Message);
                return;
            }

            if (result == null)
            {
                fbAuthenticator.OnCancelled();
            }

            DateTime?expires   = null;
            long     expiresIn = -1;

            if (result?.AccessToken.Expires != null)
            {
                expires   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(result.AccessToken.Expires.Time);
                expiresIn = (long)(expires.Value - DateTime.Now).TotalSeconds;
            }

            fbAuthenticator.OnRecievedAuthCode(result?.AccessToken.Token, expiresIn);
        }
コード例 #2
0
ファイル: Facebook.cs プロジェクト: Clancey/SimpleAuth
        public static async void Login(WebAuthenticator authenticator)
        {
            var fbAuthenticator = authenticator as FacebookAuthenticator;

            var currentActivity = activityLifecycleManager.CurrentActivity;

            FacebookSdk.SdkInitialize(currentActivity);

            callbackManager = CallbackManagerFactory.Create();
            var loginManager = LoginManager.Instance;
            var fbHandler = new FbCallbackHandler();

            loginManager.RegisterCallback(callbackManager, fbHandler);

            fbHandler.Reset();

            if (RequestPublishPermissions)
                loginManager.LogInWithPublishPermissions(currentActivity, fbAuthenticator.Scope);
            else
                loginManager.LogInWithReadPermissions(currentActivity, fbAuthenticator.Scope);

            LoginResult result = null;

            try
            {
                result = await fbHandler.Task;
            }
            catch (Exception ex)
            {
                fbAuthenticator.OnError(ex.Message);
                return;
            }

            if (result == null)
                fbAuthenticator.OnCancelled();
            
            DateTime? expires = null;
            long expiresIn = -1;
            if (result?.AccessToken.Expires != null)
            {
                expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(result.AccessToken.Expires.Time);
                expiresIn = (long)(expires.Value - DateTime.Now).TotalSeconds;
            }

            fbAuthenticator.OnRecievedAuthCode(result?.AccessToken.Token, expiresIn);
        }