Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task<string> Get(string email, string username, string password)
- {
- GlobalVariables.InstagramLogins.Remove(email);
- if (GlobalVariables.InstagramLogins.TryGetValue(email, out var api))
- {
- return Newtonsoft.Json.JsonConvert.SerializeObject(new { status = "already_logged_in" });
- }
- GlobalVariables.InstagramLogins.Remove(email);
- var appData = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\";
- string stateFile = appData + "user_states/" + InstagramExtension.CleanFromBadCharacters(email) + "_state.bin";
- // TODO Get instagram login from available accounts
- var userSession = new UserSessionData()
- {
- UserName = username,
- Password = password
- };
- // TODO GET RANDOM UNUSED PROXY
- var 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();
- // Load previous sessios if it exists
- instaApi?.SessionHandler?.Load();
- if (instaApi != null && instaApi.IsUserAuthenticated)
- {
- // session load logged us in
- GlobalVariables.InstagramLogins.Add(email, instaApi);
- return Newtonsoft.Json.JsonConvert.SerializeObject(new { status = "logged_in" });
- // return instaApi;
- }
- if (instaApi != null && !instaApi.IsUserAuthenticated)
- {
- var logInResult = await instaApi.LoginAsync();
- Debug.WriteLine(logInResult.Value);
- if (logInResult.Succeeded)
- {
- // We logged in
- // lets save the session
- instaApi.SessionHandler.Save();
- GlobalVariables.InstagramLogins.Add(email, instaApi);
- return Newtonsoft.Json.JsonConvert.SerializeObject(new { status = "logged_in" });
- //return instaApi;
- }
- if (logInResult.Value == InstaLoginResult.TwoFactorRequired)
- {
- return Newtonsoft.Json.JsonConvert.SerializeObject(new { status = "2fa_required" });
- }
- // Could not log in, lets see why
- if (logInResult.Value == InstaLoginResult.ChallengeRequired)
- {
- GlobalVariables.InstagramLogins.Add(email, instaApi);
- return Newtonsoft.Json.JsonConvert.SerializeObject(new { status = logInResult.Info.Message, loginresult = Newtonsoft.Json.JsonConvert.SerializeObject(logInResult) });
- }
- else
- {
- return Newtonsoft.Json.JsonConvert.SerializeObject(new { status = logInResult.Info.Message });
- }
- }
- return Newtonsoft.Json.JsonConvert.SerializeObject(new { status = "could_not_log_in" });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement