private void PSetApi() { //Find last login user using (var db = new DivxModel()) { var user = db.Users.FirstOrDefault(); if (user != null) { //Create user info var userSession = new UserSessionData { UserName = user.Username, Password = "******" }; //Create api APi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .Build(); //Set Session APi.LoadStateDataFromString(user.Session); } //Not user here, please login first else { MainPage.mainFrame.Navigate(typeof(View.LoginPage)); } } }
public async Task <IInstaApi> Create() { if (_api != null) { return(_api); } var api = InstaApiBuilder.CreateBuilder() .SetUser(new UserSessionData { UserName = _config.Username, Password = _config.Password }) //.UseLogger(_logger) .SetRequestDelay(RequestDelay.FromSeconds(2, 2)) .Build(); var status = await api.LoginAsync(); if (!status.Succeeded) { throw new InstaException($"Login failed with username '{_config.Username}'."); } _api = api; return(_api); }
public async Task <IInstaApi> Login(string userId, string username, string password) { var user = new UserSessionData { UserName = username, Password = password, }; var api = InstaApiBuilder.CreateBuilder().SetUser(user).SetRequestDelay(RequestDelay.FromSeconds(0, 1)).Build(); var logInResult = await api.LoginAsync(); if (!users.ContainsKey(username)) { users.Add(username, user); } if (instagrams.ContainsKey(userId)) { instagrams[userId][username] = api; } else { // instagrams[userId] = new Dictionary<string, IInstaApi>(); // instagrams[userId][username] = api; instagrams[userId] = new Dictionary <string, IInstaApi> { [username] = api, }; } return(api); }
public static async Task <LoginData?> LoadSession() { LoginData loginData = new LoginData(); try { var file = await SecureStorage.GetAsync(StateFileName); if (string.IsNullOrEmpty(file)) { return(null); } InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.Empty) .UseLogger(new DebugLogger(LogLevel.All)) .Build(); InstaApi.LoadStateDataFromString(file); if (!InstaApi.IsUserAuthenticated) { InstaApi = null; return(null); } loginData.UserName = InstaApi.GetLoggedUser().UserName; loginData.Password = InstaApi.GetLoggedUser().Password; return(loginData); } catch { InstaApi = null; return(null); } }
public async static Task Login(string username, string password) { var userSession = new UserSessionData { UserName = username, Password = password }; _instaApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.All)) // use logger for requests and debug messages .SetRequestDelay(TimeSpan.FromSeconds(0)) .Build(); if (!_instaApi.IsUserAuthenticated) { // login Console.WriteLine($"Logging in as {userSession.UserName}"); var logInResult = await _instaApi.LoginAsync(); if (!logInResult.Succeeded) { Console.WriteLine($"Unable to login: {logInResult.Info.Message}"); } } }
private async Task Login() { user.UserName = txtUsername.Text; user.Password = txtPassword.Password; this.api = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.All)) .Build(); var loginReq = await this.api.LoginAsync(); if (loginReq.Succeeded) { var home = new HomeWindow(api); home.Width = this.Width; home.Height = this.Height; home.Left = this.Left; home.Top = this.Top; home.Closed += Home_Closed; home.Show(); this.Visibility = Visibility.Hidden; } else { var result = MessageBox.Show($"Login Falied. {Environment.NewLine}Try again?", "Login Failed", MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { await Login(); } } }
private async void Login() { try { // создаем обьект, через который происходит основная работа api = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .SetRequestDelay(RequestDelay.FromSeconds(7, 9)) .Build(); var loginRequest = await api.LoginAsync(); if (loginRequest.Succeeded) { logBox.Items.Add("Logged in succes, press Start"); btn_start.Enabled = true; btn_unfollow.Enabled = true; } else { logBox.Items.Add("Logged in failed! " + loginRequest.Info.Message); } } catch (Exception ex) { logger.CloseLog(); MessageBox.Show(ex.ToString()); } }
public void CreateApiInstanceWithBuilder() { var result = new InstaApiBuilder() .UseLogger(new TestLogger()) .Build(); Assert.NotNull(result); }
public static IInstaApi BuildApi(string username = null, string password = null) { UserSessionData sessionData; if (string.IsNullOrEmpty(username)) { sessionData = UserSessionData.ForUsername("FAKEUSER").WithPassword("FAKEPASS"); } else { sessionData = new UserSessionData { UserName = username, Password = password } }; DebugLogger = new DebugLogger(LogLevel.All); var api = InstaApiBuilder.CreateBuilder() .SetUser(sessionData) //.SetDevice(new UniversalDevice()) #if DEBUG .UseLogger(DebugLogger) #endif .Build(); return(api); }
public async Task <IResult <InstaLoginResult> > Login() { var clientHandler = new HttpClientHandler(); clientHandler.Proxy = new WebProxy(ip, port) { Credentials = new NetworkCredential(_proxyUserName, _proxyPassword) }; _user.UserName = _username; _user.Password = _password; _user.CsrfToken = "LQKVEEt9LEtmZz36IYa4vJzLxLGjUv3G"; _user.RankToken = "8286475698_8afad275-4fca-49e6-a5e0-3b2bbfe6e9f2"; var delay = RequestDelay.FromSeconds(1, 1); //TODO: numeric_up_down delay _api = InstaApiBuilder.CreateBuilder() .SetUser(_user) .UseLogger(new DebugLogger(LogLevel.All)) .UseHttpClientHandler(clientHandler) .SetRequestDelay(delay) .Build(); var loginRequest = await _api.LoginAsync(); return(loginRequest); //var re = (await _api.ResetChallenge()).Value.StepData.Email = "*****@*****.**"; //var re2 = await _api.ResetChallenge(); //var verify_result = await _api.ChooseVerifyMethod(1); }
private static async Task <bool> IsUserSessionStored() { try { if (InstaApi != null) { InstaApi = null; return(false); } var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("UserSession.dat", CreationCollisionOption.OpenIfExists); var r = await FileIO.ReadTextAsync(file); string User = "******"; string Pass = "******"; //LoadUserInfo(out User, out Pass); //if (User == null || Pass == null) return false; InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(new UserSessionData { UserName = User, Password = Pass }) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .Build(); InstaApi.LoadStateDataFromStream(r); if (!InstaApi.IsUserAuthenticated) { await InstaApi.LoginAsync(); } return(true); } catch (Exception ex) { InstaApi = null; return(false); } }
public static async Task <IInstaApi> GetApi() { var instaApi = InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.Empty) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .Build(); const string stateFile = "state.bin"; if (File.Exists(stateFile)) { using (var fs = File.OpenRead(stateFile)) { instaApi.LoadStateDataFromString(new StreamReader(fs).ReadToEnd()); } } else { return(null); } if (!instaApi.IsUserAuthenticated) { var logInResult = await instaApi.LoginAsync(); if (!logInResult.Succeeded) { return(instaApi); } } return(instaApi); }
public static IInstaApi BuildApi(string username = null, string password = null) { UserSessionData sessionData; if (string.IsNullOrEmpty(username)) { sessionData = UserSessionData.ForUsername("FAKEUSER").WithPassword("FAKEPASS"); } else { sessionData = new UserSessionData { UserName = username, Password = password } }; DebugLogger = new DebugLogger(LogLevel.All); var api = InstaApiBuilder.CreateBuilder() .SetUser(sessionData) #if DEBUG .UseLogger(DebugLogger) #endif .Build(); api.SetTimeout(TimeSpan.FromMinutes(2)); //InstaApi = api; return(api); }
/// <summary> /// Load InstaApi session /// </summary> async void LoadSession() { try { var file = await LocalFolder.GetFileAsync(StateFileName); var json = await FileIO.ReadTextAsync(file); if (string.IsNullOrEmpty(json)) { return; } var userSession = new UserSessionData { // no need to set username password // but we have to set something in it UserName = "******", Password = "******" }; InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .Build(); InstaApi.LoadStateDataFromString(json); if (!InstaApi.IsUserAuthenticated) { InstaApi = null; return; } UsernameText.Text = InstaApi.GetLoggedUser().UserName; PasswordText.Password = InstaApi.GetLoggedUser().Password; "Connected".ChangeAppTitle(); } catch { InstaApi = null; } }
public async Task DoShow() { var result = await _instaApi.GetCurrentUserAsync(); if (!result.Succeeded) { Console.WriteLine($"Unable to get current user using current API instance: {result.Info}"); return; } Console.WriteLine($"Got current user: {result.Value.UserName} using existing API instance"); var stream = _instaApi.GetStateDataAsStream(); var anotherInstance = InstaApiBuilder.CreateBuilder() .SetRequestDelay(TimeSpan.FromSeconds(2)) .Build(); anotherInstance.LoadStateDataFromStream(stream); var anotherResult = await anotherInstance.GetCurrentUserAsync(); if (!anotherResult.Succeeded) { Console.WriteLine($"Unable to get current user using current API instance: {result.Info}"); return; } Console.WriteLine( $"Got current user: {anotherResult.Value.UserName} using new API instance without re-login"); }
public static IInstaApi BuildApi(string username = null, string password = null) { UserSessionData sessionData; if (string.IsNullOrEmpty(username)) { sessionData = UserSessionData.ForUsername("FAKEUSER").WithPassword("FAKEPASS"); } else { sessionData = new UserSessionData { UserName = username, Password = password } }; DebugLogger = new DebugLogger(LogLevel.All); //var delay = RequestDelay.FromSeconds(2, 4); var api = InstaApiBuilder.CreateBuilder() .SetUser(sessionData) //.SetApiVersion(InstagramApiSharp.Enums.InstaApiVersionType.Version64) //.SetRequestDelay(delay) #if DEBUG .UseLogger(DebugLogger) #endif .Build(); api.SetTimeout(TimeSpan.FromMinutes(2)); //InstaApi = api; return(api); }
async Task Login() { api = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .Build(); var loginRequest = await api.LoginAsync(); if (loginRequest.Succeeded) { IResult <InstaCurrentUser> result = await api.GetCurrentUserAsync(); var names = result.Value.FullName.Split(' '); string firstname = names[0]; string secondName = secondName = names[1]; string mail = result.Value.Email; string telNumber = result.Value.PhoneNumber; byte[] image; using (WebClient client = new WebClient()) { client.DownloadFile(new Uri(result.Value.HdProfilePicture.Uri), User.filename); } using (System.IO.FileStream fs = new System.IO.FileStream(User.filename, System.IO.FileMode.OpenOrCreate)) { image = new byte[fs.Length]; fs.Read(image, 0, image.Length); } string about = result.Value.FullName + "\n" + result.Value.Gender + "\n" + result.Value.UserName + "\n" + result.Value.CountryCode; tmp = new User(firstname, secondName, mail, telNumber, about, image); } }
public static async void Like(string userExp, string userName, string password) { user = new UserSessionData(); user.UserName = userName; user.Password = password; api = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.Exceptions)) //.SetRequestDelay(TimeSpan.FromSeconds(1)) .Build(); var loginRequest = await api.LoginAsync(); IResult <InstaUser> userSearch = await api.GetUserAsync(userExp); IResult <InstaMediaList> media = await api.GetUserMediaAsync(userExp, PaginationParameters.MaxPagesToLoad(5)); var mediaList = media.Value; int count_mediaList = mediaList.ToArray().Length; for (int i = 0; i < count_mediaList; i++) { var res = await api.LikeMediaAsync(mediaList[i].InstaIdentifier); string result = res.Succeeded.ToString(); } }
public async Task DoShow() { var result = await InstaApi.GetCurrentUserAsync(); if (!result.Succeeded) { Console.WriteLine($"Unable to get current user using current API instance: {result.Info}"); return; } Console.WriteLine($"Got current user: {result.Value.UserName} using existing API instance"); var stream = InstaApi.GetStateDataAsStream(); //// for .net core you should use this method: // var json = _instaApi.GetStateDataAsString(); var anotherInstance = InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.Empty) .SetRequestDelay(RequestDelay.FromSeconds(2, 2)) .Build(); anotherInstance.LoadStateDataFromStream(stream); //// for .net core you should use this method: // anotherInstance.LoadStateDataFromString(json); var anotherResult = await anotherInstance.GetCurrentUserAsync(); if (!anotherResult.Succeeded) { Console.WriteLine($"Unable to get current user using current API instance: {result.Info}"); return; } Console.WriteLine( $"Got current user: {anotherResult.Value.UserName} using new API instance without re-login"); }
public static async void Subs(string userExp, string userName, string password) { user = new UserSessionData(); user.UserName = userName; user.Password = password; api = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.Exceptions)) //.SetRequestDelay(TimeSpan.FromSeconds(1)) .Build(); var loginRequest = await api.LoginAsync(); IResult <InstaUser> userSearch = await api.GetUserAsync(userExp); IResult <InstaUserShortList> followers = await api.GetUserFollowersAsync(userSearch.Value.UserName, PaginationParameters.MaxPagesToLoad(5)); var followlist = followers.Value; int count_followlist = followlist.ToArray().Length; for (int i = 0; i < count_followlist; i++) { var res = await api.FollowUserAsync(followlist[i].Pk); string result = res.Succeeded.ToString(); } }
public InstagramService( IConfigurationService <InstagramServiceConfig> instaConfig, ILogger <InstagramService> logger, IUnitOfWork unitOfWork) { _instaConfig = instaConfig; _logger = logger; _userSession = new UserSessionData(); _unitOfWork = unitOfWork; var data = _instaConfig.GetSettingsAsync().Result; if (data.Password != null || data.Username != null) { _userSession.UserName = data.Username; _userSession.Password = data.Password; } else { _logger.LogError("password or username empty"); } _instaApi = InstaApiBuilder.CreateBuilder() .SetUser(_userSession) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .Build(); }
public async Task StartInstaAsync(string login, string password) { Login = login; Password = password; var userSession = new UserSessionData { UserName = Login, Password = Password }; //var httpHndler = new HttpClientHandler(); //httpHndler.Proxy = new WebProxy("vashdoom.ru", 3128); //httpHndler.Proxy = new WebProxy("92.255.195.118", 8080); InstaApi = InstaApiBuilder.CreateBuilder() .UseLogger(new DebugLogger(LogLevel.Exceptions)) .SetUser(userSession) .Build(); var loginResult = await InstaApi.LoginAsync(); if (loginResult.Succeeded == true) { IsOnline = true; } }
/// <summary> /// Load InstaApi session /// </summary> async void LoadSession() { try { var file = await LocalFolder.GetFileAsync(StateFileName); var json = await FileIO.ReadTextAsync(file); if (string.IsNullOrEmpty(json)) { return; } InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.Empty) .Build(); InstaApi.LoadStateDataFromString(json); if (!InstaApi.IsUserAuthenticated) { InstaApi = null; return; } UsernameText.Text = InstaApi.GetLoggedUser().UserName; PasswordText.Password = InstaApi.GetLoggedUser().Password; "Connected".ChangeAppTitle(); } catch { InstaApi = null; } }
public InstagramBot() { dynamic credentialJson = JsonConvert.DeserializeObject(File.ReadAllText("Credentials.json")); _userSessionData = new UserSessionData { UserName = credentialJson["INSTAGRAM_USER"], Password = credentialJson["INSTAGRAM_PASSWORD"] }; var delay = RequestDelay.FromSeconds(2, 2); _instaApi = InstaApiBuilder.CreateBuilder() .SetUser(_userSessionData) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .SetRequestDelay(delay) .Build(); try { if (File.Exists(stateFile)) { using (var fs = File.OpenRead(stateFile)) { _instaApi.LoadStateDataFromStream(fs); } } } catch (Exception e) { throw e; } }
public InstagramPublisher(IUserInputService inputService, IInstaImageToUrlConverter imageToUrlConverter) : base(new[] { ExportType.Post }) { InputService = inputService ?? throw new ArgumentNullException(nameof(inputService));; ImageToUrlConverter = imageToUrlConverter ?? throw new ArgumentNullException(nameof(imageToUrlConverter)); InstaApi = InstaApiBuilder.CreateBuilder().SetUser(new UserSessionData()).Build(); }
private async Task <bool> LoginAsync(string username, string password) { if (_api != null && _api.IsUserAuthenticated) { return(true); } var userSession = new UserSessionData { UserName = username, Password = password }; _api = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.Exceptions)).Build(); var loginRequest = await _api.LoginAsync(); if (loginRequest.Succeeded) { Console.WriteLine("Logged in!"); } else { var errorMsg = loginRequest.Info.Message; Console.WriteLine("Error Logging in!" + Environment.NewLine + errorMsg); if (errorMsg == "Please wait a few minutes before you try again.") { Thread.Sleep(TimeSpan.FromMinutes(5)); } } return(loginRequest.Succeeded); }
} = DateTime.MinValue; //время стопа //Biulder public void Biueld() { var userSession = new UserSessionData { UserName = UserName, Password = Password }; //Api = new InstaApiBuilder().SetUser(userSession).Build(); using (var db = new AppContext()) { var CurrentProxyDB = db.ProxyDBs.SingleOrDefault(p => p.ChartID == ChartID); if (CurrentProxyDB == null) { var CurrentProxyDB1 = db.ProxyDBs.Where(p => p.ChartID == 0).FirstOrDefault(); if (CurrentProxyDB1 == null) { Helper.AddEvent("Внимание", ChartID.ToString(), "Кончились прокси"); } else { CurrentProxyDB1.ChartID = ChartID; //-------------------------------- var httpHndler = new HttpClientHandler(); httpHndler.Proxy = new WebProxy(CurrentProxyDB1.IpAdress, Convert.ToInt32(CurrentProxyDB1.Port)); httpHndler.Proxy.Credentials = new NetworkCredential(CurrentProxyDB1.Login, CurrentProxyDB1.Pass); HttpClient client = new HttpClient(httpHndler) { BaseAddress = new Uri(String.Format("http://{0}:{1}/", CurrentProxyDB1.IpAdress, Convert.ToInt32(CurrentProxyDB1.Port))) }; Api = new InstaApiBuilder() .SetUser(userSession) .UseHttpClient(client) .UseHttpClientHandler(httpHndler) .Build(); } } else { var httpHndler = new HttpClientHandler(); httpHndler.Proxy = new WebProxy(CurrentProxyDB.IpAdress, Convert.ToInt32(CurrentProxyDB.Port)); httpHndler.Proxy.Credentials = new NetworkCredential(CurrentProxyDB.Login, CurrentProxyDB.Pass); HttpClient client = new HttpClient(httpHndler) { BaseAddress = new Uri(String.Format("http://{0}:{1}/", CurrentProxyDB.IpAdress, Convert.ToInt32(CurrentProxyDB.Port))) }; Api = new InstaApiBuilder() .SetUser(userSession) .UseHttpClient(client) .UseHttpClientHandler(httpHndler) .Build(); //Используем CurrentProxyDB } db.SaveChanges(); } }
private async void LoginAsync() { UserSessionData User = new UserSessionData() { UserName = UserName, Password = Password }; AppCore.InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(User) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .Build(); var loginres = await AppCore.InstaApi.LoginAsync(); switch (loginres.Value) { case InstaLoginResult.ChallengeRequired: await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate { AppCore.SaveUserInfo(User.UserName, User.Password, false); MainPage.MainFrame.Navigate(typeof(ChallengeView)); }); break; case InstaLoginResult.Success: await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate { AppCore.SaveUserInfo(User.UserName, User.Password); MainPage.MainFrame.Navigate(typeof(MainView)); }); break; case InstaLoginResult.BadPassword: await new MessageDialog(loginres.Info.Message).ShowAsync(); break; case InstaLoginResult.InvalidUser: await new MessageDialog(loginres.Info.Message).ShowAsync(); break; case InstaLoginResult.TwoFactorRequired: await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate { AppCore.SaveUserInfo(User.UserName, User.Password, false); MainPage.MainFrame.Navigate(typeof(TwoStepFactorView)); }); break; case InstaLoginResult.Exception: await new MessageDialog(loginres.Info.Exception.Message).ShowAsync(); break; default: break; } }
internal Account() { _api = InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.Empty) .SetRequestDelay(RequestDelay.FromSeconds(0, 1)) .Build(); _api.SetApiVersion(InstaApiVersionType.Version126); }
private void ConfigureDi() { this.kernel = new StandardKernel(); kernel.Bind <IInstaApiBuilder>().ToMethod(context => InstaApiBuilder.CreateBuilder()).InSingletonScope(); kernel.Bind <IApiWrapperBuilder>().To <ApiWrapperBuilder>().InSingletonScope(); kernel.Bind <IMapper>().ToMethod(a => new Mapper(mapperConfiguration)).InSingletonScope(); }