Esempio n. 1
0
        public async Task InstagramLogin()
        {
            if (!api.IsUserAuthenticated)
            {
                await api.SendRequestsBeforeLoginAsync();

                var logResult = await api.LoginAsync();

                if (logResult.Succeeded)
                {
                    Console.WriteLine("----- LOGIN RIUSCITO -----");
                    await api.SendRequestsAfterLoginAsync();

                    await App.Current.MainPage.DisplayAlert("LOGIN RIUSCITO", "goditi l'app", "OK");
                }
                else
                {
                    Console.WriteLine("------ LOGIN FALLITO ------");
                    await App.Current.MainPage.DisplayAlert("LOGIN FALLITO", "ricontrolla i dati", "OK");
                }
            }
            else
            {
                Console.WriteLine("LOGIN GIA' EFFETTUATO", "goditi l'app", "OK");
            }
        }
Esempio n. 2
0
        private async void LoginButton_Click(object sender, EventArgs e)
        {
            Size = NormalSize;
            var userSession = new UserSessionData
            {
                UserName = txtUser.Text,
                Password = txtPass.Text
            };

            InstaApi = InstaApiBuilder.CreateBuilder()
                       .SetUser(userSession)
                       .UseLogger(new DebugLogger(LogLevel.All))
                       .SetRequestDelay(RequestDelay.FromSeconds(0, 1))
                       // Session handler, set a file path to save/load your state/session data
                       .SetSessionHandler(new FileSessionHandler()
            {
                FilePath = StateFile
            })
                       .Build();
            Text = $"{AppName} Connecting";
            //Load session
            LoadSession();
            if (!InstaApi.IsUserAuthenticated)
            {
                // Call this function before calling LoginAsync
                await InstaApi.SendRequestsBeforeLoginAsync();

                // wait 5 seconds
                await Task.Delay(5000);

                var logInResult = await InstaApi.LoginAsync();

                Debug.WriteLine(logInResult.Value);
                if (logInResult.Succeeded)
                {
                    GetFeedButton.Visible = true;
                    Text = $"{AppName} Connected";

                    // Call this function after a successful login
                    await InstaApi.SendRequestsAfterLoginAsync();

                    // Save session
                    SaveSession();
                }
                else
                {
                    if (logInResult.Value == InstaLoginResult.ChallengeRequired)
                    {
                        var challenge = await InstaApi.GetChallengeRequireVerifyMethodAsync();

                        if (challenge.Succeeded)
                        {
                            if (challenge.Value.SubmitPhoneRequired)
                            {
                                SubmitPhoneChallengeGroup.Visible = true;
                                Size = ChallengeSize;
                            }
                            else
                            {
                                if (challenge.Value.StepData != null)
                                {
                                    if (!string.IsNullOrEmpty(challenge.Value.StepData.PhoneNumber))
                                    {
                                        RadioVerifyWithPhoneNumber.Checked = false;
                                        RadioVerifyWithPhoneNumber.Visible = true;
                                        RadioVerifyWithPhoneNumber.Text    = challenge.Value.StepData.PhoneNumber;
                                    }
                                    if (!string.IsNullOrEmpty(challenge.Value.StepData.Email))
                                    {
                                        RadioVerifyWithEmail.Checked = false;
                                        RadioVerifyWithEmail.Visible = true;
                                        RadioVerifyWithEmail.Text    = challenge.Value.StepData.Email;
                                    }

                                    SelectMethodGroupBox.Visible = true;
                                    Size = ChallengeSize;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show(challenge.Info.Message, "ERR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (logInResult.Value == InstaLoginResult.TwoFactorRequired)
                    {
                        TwoFactorGroupBox.Visible = true;
                        Size = ChallengeSize;
                    }
                }
            }
            else
            {
                Text = $"{AppName} Connected";
                GetFeedButton.Visible = true;
            }
        }