public static async Task <bool> Initialization(Stream data, string uname = "Queen", string pword = "Saigon") { Err = ""; InstaApi = InstaSharper.API.Builder.InstaApiBuilder.CreateBuilder() .SetUser(new UserSessionData() { UserName = uname, Password = pword }) .SetRequestDelay(RequestDelay.FromSeconds(1, 2)) .Build(); InstaApi.LoadStateDataFromStream(data); if (InstaApi.IsUserAuthenticated) { var Result = await InstaApi.GetCurrentUserAsync(); if (Result.Succeeded) { Initialized = true; Userid = Result.Value.Pk; Username = Result.Value.UserName; return(true); } else { Err = "خطا در تایید هویت حساب لطفا دوباره سعی کنید یا دوباره وارد شوید"; return(false); } } else { Err = "خطا در تایید هویت حساب لطفا دوباره سعی کنید یا دوباره وارد شوید"; return(false); } }
public static async Task <string> UploadVideo(InstagramData instagramData) { var userSession = new UserSessionData { UserName = instagramData.Username, Password = instagramData.Password }; var delay = RequestDelay.FromSeconds(2, 2); var api = GetApi(delay, userSession); loadSessionData(api); var(successLogin, possibleMessage) = await LoginIfUnauthorised(api, delay); if (!successLogin) { return(possibleMessage); } UpdateLoginState(api); var videoUpload = CreateNewVideoUpload(instagramData.VideoPath, instagramData.ImagePath); var result = await api.MediaProcessor.UploadVideoAsync(videoUpload, instagramData.Comments); return(result.Succeeded ? $"Uploaded Successfully, Media created {result.Info.Message}" : $"Unable to upload video: {result.Info.Message}"); }
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 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 void DelayDisableTest() { var delay = RequestDelay.FromSeconds(1, 2); delay.Disable(); Assert.False(delay.Exist); }
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 void DelaySameValueTest() { var s = 5; var delay = RequestDelay.FromSeconds(s, s); Assert.True(delay.Value.Seconds == s); }
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 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 IInstaApi CreateInstaInstance(UserSessionData userSessionData) { return(InstaApiBuilder.CreateBuilder() .SetUser(userSessionData) .UseLogger(new DebugLogger(LogLevel.All)) .SetRequestDelay(RequestDelay.FromSeconds(min: 0, max: 1)) .Build()); }
public void DelayDisableValueTest() { var s = 5; var delay = RequestDelay.FromSeconds(s, s); delay.Disable(); Assert.Equal(TimeSpan.Zero, delay.Value); }
internal Account() { _api = InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.Empty) .SetRequestDelay(RequestDelay.FromSeconds(0, 1)) .Build(); _api.SetApiVersion(InstagramApiSharp.Enums.InstaApiVersionType.Version126); }
/// <summary> /// Вход в аккаунт /// </summary> /// <returns></returns> public async Task SignIn() { var delay = RequestDelay.FromSeconds(2, 2); var relatedPath = Environment.CurrentDirectory + PathContract.pathAccount + userSession.UserName + PathContract.stateFile; try { if (File.Exists(relatedPath)) { Console.WriteLine("Loading state from file"); using (var fs = File.OpenRead(relatedPath)) { InstaApi.LoadStateDataFromStream(fs); } } else { var currentUser = await InstaApi.LoginAsync(); if (currentUser.Succeeded) { SaveSession(); } else { await GetChallenge(); SaveSession(); } } } catch (Exception e) { Console.WriteLine(e); throw; } LoadSession(); if (!InstaApi.IsUserAuthenticated) { var currentUser = await InstaApi.LoginAsync(); if (currentUser.Succeeded) { SaveSession(); } else { await GetChallenge(); SaveSession(); LoadSession(); } } else { Console.WriteLine("Session loaded!"); } }
private async void LoginButton_Click(object sender, EventArgs e) { Size = NormalSize; var userSession = new UserSessionData { UserName = txtUsername.Text, Password = txtPassword.Text }; InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .SetRequestDelay(RequestDelay.FromSeconds(0, 1)) .Build(); Text = $"{AppName} Connecting"; try { if (File.Exists(StateFile)) { Debug.WriteLine("Loading state from file"); using (var fs = File.OpenRead(StateFile)) { InstaApi.LoadStateDataFromStream(fs); } } } catch (Exception ex) { Debug.WriteLine(ex); } if (!InstaApi.IsUserAuthenticated) { var logInResult = await InstaApi.LoginAsync(); Debug.WriteLine(logInResult.Value); if (logInResult.Succeeded) { Text = $"{AppName} Connected"; // Save session SaveSession(); } else { // two factor is required if (logInResult.Value == InstaLoginResult.TwoFactorRequired) { // open a box so user can send two factor code Size = TwoFactorSize; } } } else { Text = $"{AppName} Connected"; } }
/// <summary> /// Insta Giriş Yapma /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Button_InstaGirisYap_Click(object sender, EventArgs e) { // Session Başlatma var userSession = new UserSessionData { UserName = textBox_InstaGiris_kadi.Text, Password = textBox_InstaGiris_Sifre.Text }; string StateYol = StateFile; // dosya var mı kontrol et varsa eğer sil if (File.Exists(StateYol)) { File.Delete(StateYol); } // Oturum oluşturma InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .SetRequestDelay(RequestDelay.FromSeconds(0, 1)) .SetSessionHandler(new FileSessionHandler() { FilePath = StateYol }) .Build(); LoadSession(); // Giriş kontrolü if (!InstaApi.IsUserAuthenticated) { // Başarısız // Giriş çıktısı var logInResult = await InstaApi.LoginAsync(); // Başarılı mı? if (logInResult.Succeeded) { // Bilgi Mesajı BilgiMesaji("basarili", "Giriş yapıldı.", this.Text, true); SaveSession(); } else { // Bilgi Mesajı BilgiMesaji("basarili", "Giriş yapılamadı.", this.Text, true); } } else { // Bilgi Mesajı BilgiMesaji("basarili", "Giriş yapıldı.", this.Text, true); SaveSession(); } }
public static IInstaApi GetDefaultInstaApiInstance(UserSessionData user) { var apiInstance = InstaApiBuilder.CreateBuilder() .SetUser(user) .SetRequestDelay(RequestDelay.FromSeconds(5, 5)) .Build(); return(apiInstance); }
protected void LikeButton_Click1(object sender, EventArgs e) { string url = UrlText.Text; long id = shortcodeToInstaID(url); string Id = id.ToString(); LikeButton.Text = Id; DataTable dt = new DataTable(); dt = db.Fill("select * from Userstbl "); for (int i = 0; i < dt.Rows.Count; i++) { var userSession = new UserSessionData { UserName = dt.Rows[i]["Username"].ToString(), Password = dt.Rows[i]["Password"].ToString() }; var delay = RequestDelay.FromSeconds(2, 2); ınstagramApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.Exceptions)) // use logger for requests and debug messages .SetRequestDelay(delay) //.SetDevice(androidDevice); .SetSessionHandler(new FileSessionHandler() { FilePath = StateFile }) .Build(); var r = Task.Run(() => ınstagramApi.LoginAsync()); if (r.Result.Succeeded) { LikeButton.Text = "Login"; } // var z = Task.Run(() => ınstagramApi.MediaProcessor.GetMediaIdFromUrlAsync(uri)); // string ID = z.Result.Value; //string id = "2372503629901614370"; var x = Task.Run(() => ınstagramApi.MediaProcessor.LikeMediaAsync(Id)); //if (x.Result.Succeeded) //{ // LikeButton.Text = "Liked Successfully"; //} } //LoadSession(); }
//登录账号 public static async System.Threading.Tasks.Task InsLoginAsync() { #region 登录Ins Console.WriteLine("登录Ins..."); var userSession = new UserSessionData { UserName = "******", Password = "******" }; var delay = RequestDelay.FromSeconds(2, 2); InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.All)) .SetRequestDelay(delay) .Build(); const string stateFile = "state.bin"; try { if (System.IO.File.Exists(stateFile)) { Console.WriteLine("从文件加载登录."); using (var fs = System.IO.File.OpenRead(stateFile)) { InstaApi.LoadStateDataFromStream(fs); } } } catch (Exception e) { Console.WriteLine(e); } if (!InstaApi.IsUserAuthenticated) { // login Console.WriteLine($"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}"); } } var state = InstaApi.GetStateDataAsStream(); using (var fileStream = System.IO.File.Create(stateFile)) { state.Seek(0, SeekOrigin.Begin); state.CopyTo(fileStream); } Console.WriteLine("已登录"); #endregion }
private void CreateInstaApi(string userName, string password) { _instaApi = InstaApiBuilder.CreateBuilder() .SetRequestDelay(RequestDelay.FromSeconds(1, 2)) .SetUser(new UserSessionData { UserName = userName, Password = password }) .Build(); }
private static IInstaApi CreateInstaApi(byte[] cookies, int requestDelayMin, int requestDelayMax) { IRequestDelay delay = RequestDelay.FromSeconds(requestDelayMin, requestDelayMax); var instaAPI = InstaApiBuilder.CreateBuilder() .SetRequestDelay(delay) .Build(); instaAPI.LoadStateDataFromStream(new MemoryStream(cookies)); return(instaAPI); }
private async void LoadAccountHTTPSession_posting() { InitalizeProxy(PostingAccount, ref PROXY_Posting); AccountMangerRow = Login.DT_AccountManager.Select("UserName_Email='" + PostingAccount + "'").FirstOrDefault(); string stateFile = PostingAccount.GetHashCode().ToString(); var userSession = new UserSessionData { UserName = PostingAccount, Password = AccountMangerRow["Password"].ToString() }; var httpClientHandler = new HttpClientHandler { Proxy = PROXY_Posting }; var delay = RequestDelay.FromSeconds(2, 2); PinApi_posing = PinApiBuilder.CreateBuilder().SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.All)) // use logger for requests and debug messages .UseHttpClientHandler(httpClientHandler) .SetRequestDelay(delay) .Build(); try { if (File.Exists(stateFile)) { using (var fs = File.OpenRead(stateFile)) { PinApi_posing.LoadStateDataFromStream(fs); } } else { var logvar = await PinApi_posing.LoginAsync(); var state = PinApi_posing.GetStateDataAsStream(); using (var fileStream = File.Create(stateFile)) { state.Seek(0, SeekOrigin.Begin); state.CopyTo(fileStream); } } } catch (Exception ex) { Login.MainInstance.LogReport(true, PostingAccount, "Http Sesstion " + ex.Message); Login.MainInstance.GridControl_Tasks.BeginInvoke(new Action(() => { TaskMangerRow["Errors"] = (int.Parse(TaskMangerRow["Errors"].ToString()) + 1); })); } }
public Account(UserSessionData userSession) { this.userSession = userSession; InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.All)) // use logger for requests and debug messages .SetRequestDelay(RequestDelay.FromSeconds(2, 2)) //отсрочка запросов .SetSessionHandler(new FileSessionHandler() { FilePath = (Environment.CurrentDirectory + PathContract.pathAccount + userSession.UserName + PathContract.stateFile) }) .Build(); }
IInstaApi BuildApi() { return(InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.ForUsername("FAKEUSERNAME").WithPassword("FAKEPASS")) .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()); }
IInstaApi BuildApi() { return(InstaApiBuilder.CreateBuilder() .SetUser(UserSessionData.Empty) .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()); }
public async Task AuthAsync(string login, string password) { InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(new UserSessionData { UserName = login, Password = password }) .SetRequestDelay(RequestDelay.FromSeconds(0, 2)) .Build(); RiseAuthStateChanged(await TryAuthAsync()); }
public static async Task <bool> Login(string uname, string pword) { Err = ""; InstaApi = InstaSharper.API.Builder.InstaApiBuilder.CreateBuilder() .SetUser(new UserSessionData() { UserName = uname, Password = pword }) .SetRequestDelay(RequestDelay.FromSeconds(1, 2)) .Build(); var loginResult = await InstaApi.LoginAsync(); //if (loginResult.Info.Message == "Challenge is required") //{ // var resgv = await InstaApi.GetVerifyStep(); // var resvm = await InstaApi.ChooseVerifyMethod(1); // var resvc = await InstaApi.SendVerifyCode("832549"); // if (resvc.Succeeded) // { // return true; // } //} if (loginResult.Succeeded) { if (InstaApi.IsUserAuthenticated) { //var StateData = InstaApi.GetStateDataAsStream(); //var accountsFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Accounts"); //var instagramFolder = await accountsFolder.GetFolderAsync("Instagram"); //var loginsFolder = await instagramFolder.GetFolderAsync("Logins"); //var loginFile = await loginsFolder.CreateFileAsync(uname + ".logininfo", CreationCollisionOption.ReplaceExisting); //await FileIO.WriteBytesAsync(loginFile, (StateData as MemoryStream).ToArray()); return(true); } else { Err = "خطا در تایید هویت حساب شما لطفا از طریق نرم افزار موبایل یا وبسایت وارد شوید سپس دوباره امتحان کنید"; return(false); } } else { Err = "نام کاربری یا کلمه عبور اشتباه است"; return(false); } }
public static async Task <bool> MainAsync() { try { // create user session data and provide login details. var userSession = new UserSessionData { UserName = userLogin, Password = userPassword }; 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(); // authentification. if (!_instaApi.IsUserAuthenticated) { // login Console.WriteLine($"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}"); return(false); } else { return(true); } } } catch (Exception ex) { Console.WriteLine(ex); } finally { // perform that if user needs to logged out // var logoutResult = Task.Run(() => _instaApi.LogoutAsync()).GetAwaiter().GetResult(); // if (logoutResult.Succeeded) Console.WriteLine("Logout succeed"); } return(false); }
public async Task Run() { if (!CheckOK(false)) { return; } var user = new UserSessionData { UserName = Login, Password = this.Password }; if (api == null) { api = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .SetRequestDelay(RequestDelay.FromSeconds(1, 3)) .Build(); } var succ = await api.LoginAsync(); if (!succ.Succeeded) { Task.Factory.StartNew(() => MessageBox.Show("Ошибка: " + succ.Info.Message, "Персонаж: " + name)); return; } var curUser = await api.GetCurrentUserAsync(); if (!curUser.Succeeded) { Task.Factory.StartNew(() => MessageBox.Show("Ошибка: " + curUser.Info.Message, "Персонаж: " + name)); return; } working = true; Task[] tasks = { FirstMessages(), Answer(curUser.Value) }; await Task.WhenAll(tasks); //await FirstMessages(); //await Answer(curUser.Value.Pk); await api.LogoutAsync(); }
public Account(UserSessionData userSession, HttpClientHandler proxy, ProxyData data) { proxydata = data; this.userSession = userSession; InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(userSession) .UseLogger(new DebugLogger(LogLevel.All)) .SetRequestDelay(RequestDelay.FromSeconds(2, 2)) .SetSessionHandler(new FileSessionHandler() { FilePath = (Environment.CurrentDirectory + PathContract.pathAccount + userSession.UserName + PathContract.stateFile) }) .UseHttpClientHandler(proxy) .Build(); }
public InstaService(ILogger logger, string userName, string password) { this.logger = logger; user = new UserSessionData(); user.UserName = userName; user.Password = password; instaApi = InstaApiBuilder.CreateBuilder() .SetUser(user) .UseLogger(new DebugLogger(LogLevel.Info)) .SetRequestDelay(RequestDelay.FromSeconds(1, 3)) .Build(); Task.Run(Login).Wait(); }