question

SaeedPooladzadeh-4680 avatar image
0 Votes"
SaeedPooladzadeh-4680 asked ZhiLv-MSFT commented

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

Hi
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="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;
  }

}


dotnet-aspnet-core-blazor
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SaeedPooladzadeh-4680,

Whether your application is an Asp.net Core web application or not? Try to set a break point in your code and step by step to debug your code to check if there have any error or exception. Besides, please refer the InstagramApi document and InstaSharp document, it is being developed in C# for .NET Framework 4.5.2 and .NET Standard 2.0, not sure if it applies to the Asp.net Core application. Since this issue relate InstaSharper, I suggest you could post your question on InstaSharper forum.

0 Votes 0 ·

0 Answers