Exemple #1
0
        private async void FacebookWebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs args)
        {
            if (FacebookLoginHelper.FirstStep(args.Url))
            {
                if (FacebookFirstTime)
                {
                    FacebookFirstTime = false;
                    FacebookTimer.Start();
                }
                else
                {
                    var cookies  = GetUriCookies(FacebookLoginHelper.InstagramUriAddress);
                    var html     = FacebookWebBrowser.DocumentText;
                    var response = FacebookLoginHelper.GetLoggedInUserResponse(html);
                    if (response != null && response.Config != null && response.Config.Viewer != null)
                    {
                        var username = response.Config.Viewer.Username;
                        // logged in successfully
                        FacebookWebBrowser.Visible = false;
                        // we don't have password so we fill it up with fake password
                        var userSession = new UserSessionData
                        {
                            UserName = username,
                            Password = "******"
                        };
                        // note: you cannot change password while you logged in with facebook account.


                        // build InstaApi
                        InstaApi = InstaApiBuilder.CreateBuilder()
                                   .SetUser(userSession)
                                   .UseLogger(new DebugLogger(LogLevel.Exceptions))
                                   .SetRequestDelay(RequestDelay.FromSeconds(0, 1))
                                   .Build();
                        LoadingPanel.Visible = false;
                        // pass information to InstaApi
                        var result = await InstaApi.SetCookiesAndHtmlForFacebookLogin(response, cookies, true);

                        if (result.Value)
                        {
                            // Save session
                            var state = InstaApi.GetStateDataAsStream();
                            using (var fileStream = File.Create(StateFile))
                            {
                                state.Seek(0, SeekOrigin.Begin);
                                state.CopyTo(fileStream);
                            }
                            // save session as json
                            //var str = InstaApi.GetStateDataAsString();
                            //File.WriteAllText("abc.json", str);
                            // visible get some feed button
                            GetFeedButton.Visible = true;
                        }
                        else
                        {
                            $"An error has occured.".Output();
                        }
                    }
                }
            }
        }