示例#1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            SetTheme(Resource.Style.MyTheme);
            base.OnCreate(savedInstanceState);

            ActionBar.Hide();
            ActionBar.SetDisplayShowTitleEnabled(false);
            ActionBar.SetDisplayShowHomeEnabled(false);

            appOpenManager = new AppOpenManager(this, this);

            SetContentView(Resource.Layout.Main);

            Platform.Init(this, savedInstanceState);
            // Batteries.Init();

            var button = FindViewById <Button>(Resource.Id.myButton);

            yuklemeBar = FindViewById <ProgressBar>(Resource.Id.progressBar1);

            txtEmail    = FindViewById <EditText>(Resource.Id.tbEmail);
            txtPassword = FindViewById <EditText>(Resource.Id.tbPassword);

            CrossPermissions.Current.CheckPermissionStatusAsync <StoragePermission>();

            MobileAds.Initialize(this, "ca-app-pub-9927527797473679~9358311233");


            userSession = new UserSessionData
            {
                UserName = "",
                Password = ""
            };


            //var delay = RequestDelay.FromSeconds(2, 2);
            // create new InstaApi instance using Builder
            _instaApi2 = InstaApiBuilder.CreateBuilder()
                         .SetRequestDelay(RequestDelay.FromSeconds(0, 0))
                         .Build();
            _instaApi2.SetTimeout(TimeSpan.FromMinutes(10));

            try
            {
                var status = CrossPermissions.Current.CheckPermissionStatusAsync <StoragePermission>();

                if (status.Result != PermissionStatus.Granted)
                {
                    if (CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Storage).Result)
                    {
                        Toast.MakeText(Application.Context, Resources.GetText(Resource.String.fileperrmisson),
                                       ToastLength.Long)
                        .Show();
                    }

                    status = CrossPermissions.Current.RequestPermissionAsync <StoragePermission>();
                }

                // load session file if exists
                if (File.Exists(stateFile))
                {
                    using var fs = File.OpenRead(stateFile);
                    _instaApi2.LoadStateDataFromStream(fs);
                    if (_instaApi2.IsUserAuthenticated)
                    {
                        // var result2 = Task.Run(async () => await _instaApi2.UserProcessor.GetUserFollowingAsync(
                        //     _instaApi2.GetLoggedUser().LoggedInUser.UserName,
                        //     PaginationParameters.MaxPagesToLoad(1))).Result;
                        // var following = result2.Value;

                        var result2   = Task.Run(async() => await _instaApi2.WebProcessor.GetAccountInfoAsync());
                        var following = result2.Result;

                        if (!following.Succeeded)
                        {
                            _instaApi2.LogoutAsync();
                            File.Delete(stateFile);
                            throw new InvalidOperationException("Oturum süreniz dolmuş");
                        }

                        girisYapti(button, _instaApi2);
                    }
                }
            }
            catch (Exception er)
            {
                HataGoster(er.Message);
            }


            button.Click += butonTiklandiAsync;
        }
示例#2
0
        private async void butonTiklandiAsync(object sender, EventArgs e)
        {
            var button = sender as Button;

            var status = await CrossPermissions.Current.CheckPermissionStatusAsync <StoragePermission>();

            if (status != PermissionStatus.Granted)
            {
                if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Storage))
                {
                    Toast.MakeText(Application.Context, Resources.GetText(Resource.String.fileperrmisson),
                                   ToastLength.Long).Show();
                }

                status = await CrossPermissions.Current.RequestPermissionAsync <StoragePermission>();
            }

            yuklemeBar.Visibility = ViewStates.Visible;

            if (txtEmail.Text.Length <= 0 || txtPassword.Text.Length <= 0)
            {
                HataGoster(Resources.GetText(Resource.String.passwordempty));
                yuklemeBar.Visibility = ViewStates.Invisible;
                return;
            }

            userSession = new UserSessionData
            {
                UserName = txtEmail.Text,
                Password = txtPassword.Text
            };

            _instaApi = InstaApiBuilder.CreateBuilder()
                        .SetUser(userSession)
                        .SetRequestDelay(RequestDelay.FromSeconds(0, 0))
                        .Build();

            _instaApi.SetTimeout(TimeSpan.FromMinutes(10));


            if (!_instaApi.IsUserAuthenticated)
            {
                var logInResult = await _instaApi.LoginAsync();

                if (!logInResult.Succeeded)
                {
                    switch (logInResult.Value)
                    {
                    case InstaLoginResult.TwoFactorRequired:
                    {
                        var et = new EditText(this);
                        var ad = new AlertDialog.Builder(this);
                        et.InputType = InputTypes.ClassNumber;

                        ad.SetTitle("Two Factor Code Required");
                        ad.SetView(et);
                        ad.SetCancelable(false);

                        ad.SetPositiveButton("OK", async delegate
                            {
                                ad.Dispose();
                                yuklemeBar.Visibility = ViewStates.Visible;

                                if (et.Text == null && et.Text.Length < 5)
                                {
                                    HataGoster("2 Factor code cannot be shorter than 6");
                                }

                                var twoFactorLogin = await _instaApi.TwoFactorLoginAsync(et.Text);

                                if (twoFactorLogin.Succeeded)
                                {
                                    await girisYapti(button, _instaApi);
                                    var state2 = await _instaApi.GetStateDataAsStreamAsync();
                                    await using var fileStream2 = File.Create(stateFile);
                                    state2.Seek(0, SeekOrigin.Begin);
                                    await state2.CopyToAsync(fileStream2);
                                }
                                else
                                {
                                    Toast.MakeText(Application.Context, twoFactorLogin.Info.Message, ToastLength.Long)
                                    ?.Show();
                                    HataGoster(twoFactorLogin.Info.Message);
                                }
                            }
                                             );

                        ad.Show();
                        break;
                    }