Why I can't log into my account via instasharper(a C# wrapper for instagram)

Posted 31 days ago by lingo1357
0

Hello,

I made a site for Instagram with instasharper (C# wrapper for instagram) .
But when I try to log in to my account. I can't.
Do you think Instagram doesn't let this C# wrapper, or there is a mistake in my code:

 

<div class="container">
    <div class="row justify-content-center text-center">
        <div class="col-12">
            <p class="h4 text-primary" style="margin-top:13%;">Enter your instagram username and password</p>
        </div>

        <div class="col-md-4 col-lg-3 p-5 bg-primary" style="margin-top:5%;">

            <label for="user" class="text-white">Username:</label>
            <input type="text" class="form-control" id="uName" @bind="username" @bind:event="oninput">

            <label for="pwd" class="text-white">Password:</label>
            <input type="password" class="form-control" id="pword" @bind="password" @bind:event="oninput">

            <button type="button" class="btn btn-warning mt-3" @onclick="StartInstagram">submit</button>
        </div>

    </div>

    <div class="text-center">
    <h5 >ConsoleMessage: @ConsoleMessage</h5>
    <h5>ExceptionMessage: @ExceptionMessage</h5>
    <h5>FileExitException: @FileExitException</h5>
    <h5>FileExitConsole: @FileExitConsole</h5>
    </div>


</div>

@code{

    public static IInstaApi _instaApi;

    public static string username { get; set; }
    public static string password { get; set; }

    public bool result { get; set; } = true;
    public string message = "";
    public static string FileExitException=string.Empty;
    public static string ExceptionMessage=string.Empty;
    public static string ConsoleMessage = string.Empty;
    public static string FileExitConsole = string.Empty;



    private async Task StartInstagram()
    {


        var result = await MainAsync();
        if (result)
        {

            NavigationManager.NavigateTo("ImageUpload");


            return;
        }


    }


    public static async Task<bool> MainAsync()

    {
        try
        {
            var userSession = new UserSessionData
            {

                UserName = Enterance.username,
                Password = Enterance.password
            };


            var delay = RequestDelay.FromSeconds(2, 2);
            // create new InstaApi instance using Builder
            _instaApi = InstaApiBuilder.CreateBuilder()
                    .SetUser(userSession)
                    .UseLogger(new DebugLogger(LogLevel.Exceptions)) // use logger for requests and debug messages
                    .SetRequestDelay(delay)
                    .Build();



            const string stateFile = "state.bin";
            try
            {
                if (File.Exists(stateFile))
                {
                    //Console.WriteLine("Loading state from file");
                    FileExitConsole = "Loading state from file";


                    using (var fs = File.OpenRead(stateFile))
                    {
                        _instaApi.LoadStateDataFromStream(fs);
                    }
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                FileExitException = $" error: {e}";
            }



            //return true;
            if (!_instaApi.IsUserAuthenticated)
            {
                // login

                ConsoleMessage = $"Logging in as {userSession.UserName}";

                delay.Disable();
                var logInResult = await _instaApi.LoginAsync();
                delay.Enable();
                if (!logInResult.Succeeded)
                {
                    //Console.WriteLine($"Unable to login: {logInResult.Info.Message}");
                    ConsoleMessage = $"Unable to login: {logInResult.Info.Message}";
                    return false;
                }
            }

        }
        catch (Exception ex)
        {


            ExceptionMessage = $"Can not work:{ex}";
            //ExceptionMessage = "again problem";


        }

        return false;


    }


}
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 1
An error has occurred. This application may no longer respond until reloaded. Reload 🗙