Esempio n. 1
0
        private void WebBrowserRmtDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            if (e == null)
            {
                return;
            }
            if (e.Url == null)
            {
                return;
            }
            if (e.Url.ToString() == InstagramUri.ToString() && !IsWebBrowserInUse)
            {
                // Get cookies from WebBrowser
                var cookies = GetUriCookies(InstagramUri);

                // Pass web browser document source and cookies to this function:
                // NOTE: Don't use WebBrowserRmt.Document.Cookie to get cookies because it's not getting full cookies
                var result = InstaApi.SetCookiesAndHtmlForChallenge(WebBrowserRmt.DocumentText, cookies);
                // You are logged in
                if (result.Succeeded)
                {
                    Text = $"{AppName} Connected";
                    // Save session
                    var state = InstaApi.GetStateDataAsStream();
                    using (var fileStream = File.Create(StateFile))
                    {
                        state.Seek(0, SeekOrigin.Begin);
                        state.CopyTo(fileStream);
                    }
                }
                else
                {
                    // there is an unknown error.
                    Text = $"{AppName} couldn't login";
                }

                Thread.Sleep(1500);
                WebBrowserRmt.Stop();
                WebBrowserRmt.Visible = false;
                IsWebBrowserInUse     = true;
                Size = NormalSize;
            }
        }