Exemplo n.º 1
0
        private async void FacebookWebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs args)
        {
            try
            {
                var html = FacebookWebBrowser.DocumentText;
                if (InstaFbHelper.IsLoggedIn(html))
                {
                    var cookies = GetUriCookies(args.Url);
                    var fbToken = InstaFbHelper.GetAccessToken(html);

                    InstaApi = BuildApi();
                    Text     = $"{AppName} Connecting";
                    var loginResult = await InstaApi.LoginWithFacebookAsync(fbToken, cookies);

                    if (loginResult.Succeeded)
                    {
                        Text = $"{AppName} Connected";
                        GetFeedButton.Visible = true;
                        SaveSession();
                    }
                    else
                    {
                        switch (loginResult.Value)
                        {
                        case InstaLoginResult.BadPassword:
                            MessageBox.Show("Wrong Password");
                            break;

                        case InstaLoginResult.ChallengeRequired:
                        case InstaLoginResult.TwoFactorRequired:
                            MessageBox.Show("You must combine Challenge Example to your project");
                            break;

                        default:
                            MessageBox.Show($"ERR: {loginResult.Value}\r\n{loginResult.Info.Message}");
                            break;
                        }
                        Text = $"{AppName} ERROR";
                    }
                }
            }
            catch { }
        }
Exemplo n.º 2
0
        private async void WebViewFacebookDOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
        {
            try
            {
                SignInVM.LoadingOff();
                try
                {
                    string html = await FacebookWebView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });

                    if (InstaFbHelper.IsLoggedIn(html))
                    {
                        var cookies   = GetBrowserCookie(args.Uri);
                        var sbCookies = new StringBuilder();
                        foreach (var item in cookies)
                        {
                            sbCookies.Append($"{item.Name}={item.Value}; ");
                        }

                        var fbToken = InstaFbHelper.GetAccessToken(html);

                        Helper.InstaApiTrash = Helper.BuildApi();
                        await Helper.InstaApiTrash.SendRequestsBeforeLoginAsync();

                        SignInVM.LoadingOn();
                        var loginResult = await Helper.InstaApiTrash.LoginWithFacebookAsync(fbToken, sbCookies.ToString());

                        FacebookGrid.Visibility = Visibility.Collapsed;
                        SignInVM.HandleLogin(loginResult);
                    }
                }
                catch { }
            }
            catch (Exception ex)
            {
                ex.PrintException("WebViewFacebookDOMContentLoaded");
            }
        }