private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { IResult <InstaUserInfo> userinfo = await _instaApi.GetUserInfoByIdAsync(_userSession.LoggedInUder.Pk); IResult <InstaUser> user = await _instaApi.GetUserAsync("aeroflot"); IResult <InstaUserInfo> info = await _instaApi.GetUserInfoByIdAsync(user.Value.Pk); IResult <InstaUserShortList> folows = await _instaApi.GetUserFollowersAsync(_userSession.UserName, PaginationParameters.Empty); IResult <InstaMedia> userinfo2 = await _instaApi.GetMediaByIdAsync(folows.Value[43].ProfilePictureId); using (HttpClient client = new HttpClient()) { HttpResponseMessage imageResponse = await client.GetAsync(userinfo2.Value.Images[0].URI); //InMemoryRandomAccessStream randomAccess = new InMemoryRandomAccessStream(); //DataWriter writer = new DataWriter(randomAccess.GetOutputStreamAt(0)); //writer.WriteBytes(await imageResponse.Content.ReadAsByteArrayAsync()); //await writer.StoreAsync(); //BitmapImage bm = new BitmapImage(); //await bm.SetSourceAsync(randomAccess); //myImg.Source = bm; } }
private async Task <IndexModel> GetData(string username) { var model = new IndexModel(); model.Username = username; var followers = await _instaApi.GetUserFollowersAsync(username, PaginationParameters.Empty); var following = await _instaApi.GetUserFollowingAsync(username, PaginationParameters.Empty); if (!followers.Succeeded || !following.Succeeded) { model.Message = "User not found."; return(model); } model.Followers = followers.Value.ToList(); model.Following = following.Value.ToList(); model.FollowersNotFollowed = model.Followers.Where(x => model.Following.All(y => y.UserName != x.UserName)).ToList(); model.FollowingNotFollowers = model.Following.Where(x => model.Followers.All(y => y.UserName != x.UserName)).ToList(); model.SearchedWithSuccess = true; return(model); }
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 static async Task <InstaUserShortList> GetFollowersList(IInstaApi api) { var followers = await api.GetUserFollowersAsync(user.UserName, PaginationParameters.Empty); var followersList = followers.Value; return(followersList); }
public void DoShow() { // get currently logged in user var currentUser = _instaApi.GetCurrentUser().Value; Console.WriteLine($"Logged in: username - {currentUser.UserName}, full name - {currentUser.FullName}"); // get self followers var followers = _instaApi.GetUserFollowersAsync(currentUser.UserName, 5).Result.Value; Console.WriteLine($"Count of followers [{currentUser.UserName}]:{followers.Count}"); // get self user's media, latest 5 pages var currentUserMedia = _instaApi.GetUserMedia(currentUser.UserName, 5); if (currentUserMedia.Succeeded) { Console.WriteLine($"Media count [{currentUser.UserName}]: {currentUserMedia.Value.Count}"); foreach (var media in currentUserMedia.Value) { ConsoleUtils.PrintMedia("Self media", media, _maxDescriptionLength); } } //get user time line feed, latest 5 pages var userFeed = _instaApi.GetUserTimelineFeed(5); if (userFeed.Succeeded) { Console.WriteLine( $"Feed items (in {userFeed.Value.Pages} pages) [{currentUser.UserName}]: {userFeed.Value.Medias.Count}"); foreach (var media in userFeed.Value.Medias) { ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength); } //like first 10 medias from user timeline feed foreach (var media in userFeed.Value.Medias.Take(10)) { var likeResult = _instaApi.LikeMedia(media.InstaIdentifier); var resultString = likeResult.Value ? "liked" : "not liked"; Console.WriteLine($"Media {media.Code} {resultString}"); } } // get tag feed, latest 5 pages var tagFeed = _instaApi.GetTagFeed("quadcopter", 5); if (tagFeed.Succeeded) { Console.WriteLine( $"Tag feed items (in {tagFeed.Value.Pages} pages) [{currentUser.UserName}]: {tagFeed.Value.Medias.Count}"); foreach (var media in tagFeed.Value.Medias) { ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength); } } }
public async Task <List <UserInfo> > GetUserFollowers(string userName, int maxPageToLoad = 10) { validateInstaClient(); validateLoggedIn(); IResult <InstaUserShortList> userShortList = await instaApi.GetUserFollowersAsync(userName, PaginationParameters.MaxPagesToLoad(maxPageToLoad)); return(userShortList.Value.ToUserInfoList()); }
private static async Task <InstaUserShortList> GetFollowersList(IInstaApi api, string username) { var followers = await api.GetUserFollowersAsync(username, PaginationParameters.Empty); if (followers.Info.ResponseType != ResponseType.OK && followers.Info.Exception.Message == "Object reference not set to an instance of an object.") { throw new Exception("Please Check Your Username!"); } var followersList = followers.Value; return(followersList); }
public async void PullUserPosts(string username) { //IResult<InstaUserShortList> userFollowers = await api.GetUserFollowersAsync(username, PaginationParameters.MaxPagesToLoad(5)); var task = api.GetUserFollowersAsync(username, PaginationParameters.MaxPagesToLoad(5)); IResult <InstaUserShortList> userFollowers = task.GetAwaiter().GetResult(); Thread.Sleep(2000); for (int i = 0; i < userFollowers.Value.Count; i++) { //Console.WriteLine($"\n\t{userFollowers.Value[i].UserName}"); ScrapeUser(userFollowers.Value[i].UserName); } }
public async Task <MainLoginModel> UpdateLoginModel() { var info = await _instaApi.GetCurrentUserAsync(); var model = new MainLoginModel { CurrentUser = info.Value }; var followers = await _instaApi.GetUserFollowersAsync(info.Value.UserName, PaginationParameters.MaxPagesToLoad(15)); model.Followers = followers.Value; var following = await _instaApi.GetUserFollowingAsync(info.Value.UserName, PaginationParameters.MaxPagesToLoad(15)); model.Following = following.Value; return(model); }
public async Task Import(UserSettings settings) { try { await AuthorizeBot(settings); var result = await _instaApi.GetUserFollowersAsync(settings.TargetUsername, PaginationParameters.Empty); var followers = result.Value; var count = followers.Count; var import = new ImportList() { Date = DateTime.UtcNow, Count = followers.Count, UserId = settings.UserId, TargetName = settings.TargetUsername }; _context.ImportLists.Add(import); await _context.SaveChangesAsync(); foreach (var item in followers) { var follower = new InstaUser() { ImportId = import.Id, IsPrivate = item.IsPrivate, IsVerified = item.IsVerified, FullName = item.FullName, Pk = item.Pk, UserName = item.UserName, ProfilePicture = item.ProfilePicture, ProfilePictureId = item.ProfilePictureId }; _context.InstaUsers.Add(follower); } await _context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } }
private static async void RunUnfollowTaskAsync(TaskModel t, IInstaApi api) { t = t.Refreshed; List <InstaUserShort> users = new List <InstaUserShort>(); var _currentUser = await api.GetCurrentUserAsync(); if (_currentUser.Succeeded) { var _followers = await api.GetUserFollowersAsync(_currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(10)); if (_followers.Succeeded) { var filteredUsers = await Helper.GetFilteredUsersAsync(_followers.Value.ToList(), t.Searches, api, 5); foreach (var user in filteredUsers) { if (user != null) { var result = await api.UnFollowUserAsync(user.Pk); if (result.Succeeded) { if (!result.Value.Following) { t.TaskExecuted(); Helper.Log($"Task Executed: {t.Name} - {t.TaskType.ToString()} {Environment.NewLine} {JsonConvert.SerializeObject(result.Value)}"); } else { Helper.Log(JsonConvert.SerializeObject(result.Value)); } } } } } } }
async void Sbor() { info.File = setting.SborAcc_SaveFileName; info.Status = "Выполняется"; int progress = 0; info.Progress = $"{progress}/{setting.SborAcc_CountOneUser * setting.SborAcc_ListUserNames.Count}"; EventUpdateGrid(this, new UpdateGridAudience(info)); foreach (string username in setting.SborAcc_ListUserNames) { if (_source == null || _source.IsCancellationRequested) { break; } int maxPagesToLoad = setting.SborAcc_CountOneUser % 200 == 0 ? setting.SborAcc_CountOneUser / 200 : (setting.SborAcc_CountOneUser / 200) + 1; if (setting.SborAcc_Sbor == Audience.Sbor.Followers) { var infoFollowers = await api.GetUserFollowersAsync(username, PaginationParameters.MaxPagesToLoad(maxPagesToLoad)); ew.WaitOne(); info.Status = "Выполняется"; if (infoFollowers.Value.Count != 0 || infoFollowers.Succeeded) { for (int i = 0; i < infoFollowers.Value.Count; i++) { try { if (_source == null || _source.IsCancellationRequested) { break; } if (i > setting.SborAcc_CountOneUser) { break; } if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars && !infoFollowers.Value[i].IsPrivate) { continue; } if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars && infoFollowers.Value[i].IsPrivate) { if (setting.SborAcc_WhatPars == WhatPars.ID) { listAcc.Add(infoFollowers.Value[i].Pk.ToString()); } if (setting.SborAcc_WhatPars == WhatPars.Login) { listAcc.Add(infoFollowers.Value[i].UserName); } } if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars && infoFollowers.Value[i].IsPrivate) { continue; } if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars && !infoFollowers.Value[i].IsPrivate) { if (setting.SborAcc_WhatPars == WhatPars.ID) { listAcc.Add(infoFollowers.Value[i].Pk.ToString()); } if (setting.SborAcc_WhatPars == WhatPars.Login) { listAcc.Add(infoFollowers.Value[i].UserName); } } if (WhatAccPars.All == setting.SborAcc_WhatAccPars) { if (setting.SborAcc_WhatPars == WhatPars.ID) { listAcc.Add(infoFollowers.Value[i].Pk.ToString()); } if (setting.SborAcc_WhatPars == WhatPars.Login) { listAcc.Add(infoFollowers.Value[i].UserName); } } progress++; info.Progress = $"{progress}/{setting.SborAcc_CountOneUser * setting.SborAcc_ListUserNames.Count}"; EventUpdateGrid(this, new UpdateGridAudience(info)); } catch { continue; } } } } else { var infoFollowers = await api.GetUserFollowingAsync(username, PaginationParameters.MaxPagesToLoad(maxPagesToLoad)); ew.WaitOne(); info.Status = "Выполняется"; if (infoFollowers.Succeeded || infoFollowers.Value.Count != 0) { for (int i = 0; i < infoFollowers.Value.Count; i++) { try { if (_source == null || _source.IsCancellationRequested) { break; } if (i > setting.SborAcc_CountOneUser) { break; } if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars && !infoFollowers.Value[i].IsPrivate) { continue; } if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars && infoFollowers.Value[i].IsPrivate) { if (setting.SborAcc_WhatPars == WhatPars.ID) { listAcc.Add(infoFollowers.Value[i].Pk.ToString()); } if (setting.SborAcc_WhatPars == WhatPars.Login) { listAcc.Add(infoFollowers.Value[i].UserName); } } if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars && infoFollowers.Value[i].IsPrivate) { continue; } if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars && !infoFollowers.Value[i].IsPrivate) { if (setting.SborAcc_WhatPars == WhatPars.ID) { listAcc.Add(infoFollowers.Value[i].Pk.ToString()); } if (setting.SborAcc_WhatPars == WhatPars.Login) { listAcc.Add(infoFollowers.Value[i].UserName); } } if (WhatAccPars.All == setting.SborAcc_WhatAccPars) { if (setting.SborAcc_WhatPars == WhatPars.ID) { listAcc.Add(infoFollowers.Value[i].Pk.ToString()); } if (setting.SborAcc_WhatPars == WhatPars.Login) { listAcc.Add(infoFollowers.Value[i].UserName); } } progress++; info.Progress = $"{progress}/{setting.SborAcc_CountOneUser * setting.SborAcc_ListUserNames.Count}"; EventUpdateGrid(this, new UpdateGridAudience(info)); } catch { continue; } } } } Thread.Sleep(5000); } Save(); info.Status = "Выполнено"; EventUpdateGrid(this, new UpdateGridAudience(info)); }
private async void BeginBtn_Click(object sender, RoutedEventArgs eventArgs) { try { Console.WriteLine("Starting demo of InstaSharper project"); // create user session data and provide login details var userSession = new UserSessionData { UserName = "******", Password = "******" }; var delay = TimeSpan.FromSeconds(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(); //// create account //var username = "******"; //var password = "******"; //var email = "*****@*****.**"; //var firstName = "Ramtin"; //var accountCreation = await _instaApi.CreateNewAccount(username, password, email, firstName); const string stateFile = "state.bin"; try { if (File.Exists(stateFile)) { Console.WriteLine("Loading state from file"); using (var fs = 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}"); //return false; return; } //var state = _instaApi.GetStateDataAsStream(); //using (var fileStream = File.Create(stateFile)) //{ // state.Seek(0, SeekOrigin.Begin); // state.CopyTo(fileStream); //} var res = await _instaApi.GetUserFollowersAsync("the_samimd", PaginationParameters.MaxPagesToLoad(2)); Console.Write("he"); // Console.WriteLine("Press 1 to start basic demo samples"); // Console.WriteLine("Press 2 to start upload photo demo sample"); // Console.WriteLine("Press 3 to start comment media demo sample"); // Console.WriteLine("Press 4 to start stories demo sample"); // Console.WriteLine("Press 5 to start demo with saving state of API instance"); // Console.WriteLine("Press 6 to start messaging demo sample"); // Console.WriteLine("Press 7 to start location demo sample"); // Console.WriteLine("Press 8 to start collections demo sample"); // Console.WriteLine("Press 9 to start upload video demo sample"); // var samplesMap = new Dictionary<ConsoleKey, IDemoSample> // { // [ConsoleKey.D1] = new Basics(_instaApi), // [ConsoleKey.D2] = new UploadPhoto(_instaApi), // [ConsoleKey.D3] = new CommentMedia(_instaApi), // [ConsoleKey.D4] = new Stories(_instaApi), // [ConsoleKey.D5] = new SaveLoadState(_instaApi), // [ConsoleKey.D6] = new Messaging(_instaApi), // [ConsoleKey.D7] = new LocationSample(_instaApi), // [ConsoleKey.D8] = new CollectionSample(_instaApi), // [ConsoleKey.D9] = new UploadVideo(_instaApi) // }; // var key = Console.ReadKey(); // Console.WriteLine(Environment.NewLine); // if (samplesMap.ContainsKey(key.Key)) // await samplesMap[key.Key].DoShow(); // Console.WriteLine("Done. Press esc key to exit..."); // key = Console.ReadKey(); // return key.Key == ConsoleKey.Escape; } } 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 static async Task <bool> MainAsync() { var binFolder = configFile.AppSettings.Settings["BinFolder"].Value; Directory.CreateDirectory(binFolder); var hardFollows = configFile.AppSettings.Settings["HardFollows"].Value; var hardFollowList = hardFollows.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); var userSession = new UserSessionData { UserName = configFile.AppSettings.Settings["UserName"].Value, Password = configFile.AppSettings.Settings["Password"].Value }; var delay = RequestDelay.FromSeconds(2, 2); _instaApi = InstaApiBuilder.CreateBuilder().SetUser(userSession).SetRequestDelay(delay).Build(); var stateFilePath = binFolder + stateFile; try { if (File.Exists(stateFilePath)) { //Console.WriteLine("Loading state from file"); using (var fs = File.OpenRead(stateFilePath)) { _instaApi.LoadStateDataFromStream(fs); } } } catch (Exception e) { return(false); } if (!_instaApi.IsUserAuthenticated) { //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); } } var state = _instaApi.GetStateDataAsStream(); using (var fileStream = File.Create(stateFilePath)) { state.Seek(0, SeekOrigin.Begin); state.CopyTo(fileStream); } var currentUser = await _instaApi.GetCurrentUserAsync(); //Console.WriteLine($"Logged in: username - {currentUser.Value.UserName}, full name - {currentUser.Value.FullName}"); //var followers = await _instaApi.GetCurrentUserFollowersAsync(PaginationParameters.MaxPagesToLoad(6)); //Console.WriteLine($"Count of followers [{currentUser.Value.UserName}]:{followers.Value.Count}"); var followers = await _instaApi.GetUserFollowersAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(6)); var followersList = followers.Value.Select(p => p.UserName).ToList(); var followersListPath = binFolder + @"FollowersLists\"; Directory.CreateDirectory(followersListPath); var followerListFileFullName = followersListPath + "followersList" + now.ToString("yyyyMMddHHmmssFFFFFFF") + ".txt"; File.WriteAllLines(followerListFileFullName, followersList); var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(6)); var followingList = following.Value.Select(p => p.UserName).ToList(); var followingListPath = binFolder + @"FollowingLists\"; Directory.CreateDirectory(followingListPath); var followingListFileFullName = followingListPath + "followingList" + now.ToString("yyyyMMddHHmmssFFFFFFF") + ".txt"; File.WriteAllLines(followingListFileFullName, followingList); var msgBody = PrepareMsgBody(followingListPath, followersListPath); if (msgBody != string.Empty) { var subject = "Analiz! InstagramLooker - " + now.ToString("dd/MM/yyyy - HH:mm"); SendMail(subject, msgBody); } DeleteOldestFile(followersListPath); DeleteOldestFile(followingListPath); //Console.WriteLine($"Count of following [{currentUser.Value.UserName}]:{following.Value.Count}"); return(true); }
public async Task DoShow() { // get currently logged in user var currentUser = await _instaApi.GetCurrentUserAsync(); Console.WriteLine( $"Logged in: username - {currentUser.Value.UserName}, full name - {currentUser.Value.FullName}"); // get followers of user 'elonmusk' var followers = await _instaApi.GetUserFollowersAsync("elonmusk", PaginationParameters.MaxPagesToLoad(5) .StartFromId("AQAC8w90POWyM7zMjHWmO9vsZNL_TuLp6FR506_C_y3fUAjlCclrIDI2RdSGvur5UjLrq4Cq7NJN8QUhHG-vpbT6pCLB5X9crDxBOHUEuNJ4fA")); Console.WriteLine($"Count of followers [elonmusk]:{followers.Value.Count}"); Console.WriteLine($"Next id will be: '{followers.Value.NextId}'"); // get self folling var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(5)); Console.WriteLine($"Count of following [{currentUser.Value.UserName}]:{following.Value.Count}"); // get self user's media, latest 5 pages var currentUserMedia = await _instaApi.GetUserMediaAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(5)); if (currentUserMedia.Succeeded) { Console.WriteLine($"Media count [{currentUser.Value.UserName}]: {currentUserMedia.Value.Count}"); foreach (var media in currentUserMedia.Value) { ConsoleUtils.PrintMedia("Self media", media, _maxDescriptionLength); } } //get user time line feed, latest 5 pages var userFeed = await _instaApi.GetUserTimelineFeedAsync(PaginationParameters.MaxPagesToLoad(5)); if (userFeed.Succeeded) { Console.WriteLine( $"Feed items (in {userFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {userFeed.Value.Medias.Count}"); foreach (var media in userFeed.Value.Medias) { ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength); } //like first 10 medias from user timeline feed foreach (var media in userFeed.Value.Medias.Take(10)) { var likeResult = await _instaApi.LikeMediaAsync(media.InstaIdentifier); var resultString = likeResult.Value ? "liked" : "not liked"; Console.WriteLine($"Media {media.Code} {resultString}"); } } // get tag feed, latest 5 pages var tagFeed = await _instaApi.GetTagFeedAsync("quadcopter", PaginationParameters.MaxPagesToLoad(5)); if (tagFeed.Succeeded) { Console.WriteLine( $"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}"); foreach (var media in tagFeed.Value.Medias) { ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength); } } }
async void ClearBots() { Stat = true; userInfoLog = await api.GetCurrentUserAsync(); EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Чистка от ботов запущена")); try { if (setting.FileNameExceptionId.Length != 0) { string[] stringID = System.IO.File.ReadAllLines(setting.FileNameExceptionId); foreach (string str in stringID) { try { usersID.Add(Convert.ToInt64(str)); } catch { continue; } } } } catch (Exception e) { EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] ОШИБКА: {e.Message}")); } var userInfo = await api.GetCurrentUserAsync(); IResult <InstaUserShortList> x = null; if (setting.WhomClear.Equals("Подписчиков")) { x = await api.GetUserFollowersAsync(userInfo.Value.UserName, PaginationParameters.MaxPagesToLoad(2)); } if (setting.WhomClear.Equals("Подписки")) { x = await api.GetUserFollowingAsync(userInfo.Value.UserName, PaginationParameters.MaxPagesToLoad(2)); } if (x.Succeeded) { count = x.Value.Count; EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Выполняется")); foreach (InstaUserShort user in x.Value) { try { if (_source == null || _source.IsCancellationRequested) { break; } if (usersID.Count != 0) //Учет не отписки от определнных пользователей { bool flag = false; foreach (long id in usersID) { if (user.Pk == id) { EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Пользователь {user.UserName} пропущен. Запрет на отписку.")); Delay(); flag = true; break; } } if (flag) { continue; } } if (setting.LimitBlock <= CountBlock) //Учет лимита блокировок { EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Превышен лимит блокировок. Останавливаю процесс.")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Завершено")); return; } if (setting.ChekedPause) //Учет паузы { if (setting.PauseLimit <= CountPause) { CountPause = 0; EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Пауза на " + setting.PauseTime + " минут")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Пауза")); if (timer != null) { timer.Dispose(); } timer = new Timer(CancelDelay, null, 60000 * (int)setting.PauseTime, Timeout.Infinite); ew.Reset(); ew.WaitOne(); } } var info = await api.GetUserInfoByIdAsync(user.Pk); if (info.Succeeded == false) { Thread.Sleep(500); continue; } if (setting.CheckedNoAvatarUser) //Если нет автарки { if (info.Value.HasAnonymousProfilePicture) { await api.BlockUserAsync(user.Pk); CountBlock++; CountPause++; EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователя с ником: {user.UserName}. Количество блокировок: {CountBlock}")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Выполняется")); if (!setting.ChekedUserBlock) { await api.UnBlockUserAsync(user.Pk); EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}")); } Delay(); //Учет задержки continue; } } if (setting.CheckedPublicCountLess) //Публикаций меньше { int countPublic = Convert.ToInt32(info.Value.MediaCount); if (countPublic < setting.PublicCountLess) { await api.BlockUserAsync(user.Pk); CountBlock++; CountPause++; EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Выполняется")); if (!setting.ChekedUserBlock) { await api.UnBlockUserAsync(user.Pk); EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}")); } Delay(); //Учет задержки continue; } } if (setting.ChekedFollowsCountLess) { int countFollower = Convert.ToInt32(info.Value.FollowerCount); if (countFollower < setting.FollowsCountLess) { await api.BlockUserAsync(user.Pk); CountBlock++; CountPause++; EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Выполняется")); if (!setting.ChekedUserBlock) { await api.UnBlockUserAsync(user.Pk); EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}")); } Delay(); //Учет задержки continue; } } if (setting.ChekedSubscriptionsLess) { int countSubscriptions = Convert.ToInt32(info.Value.FollowingCount); if (countSubscriptions < setting.SubscriptionsLess) { await api.BlockUserAsync(user.Pk); CountBlock++; CountPause++; EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Выполняется")); if (!setting.ChekedUserBlock) { await api.UnBlockUserAsync(user.Pk); EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}")); } Delay(); //Учет задержки continue; } } if (setting.ChekedSubscriptionsMore) { int countSubscriptions = Convert.ToInt32(info.Value.FollowingCount); if (countSubscriptions > setting.SubscriptionMore) { await api.BlockUserAsync(user.Pk); CountBlock++; CountPause++; EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Выполняется")); if (!setting.ChekedUserBlock) { await api.UnBlockUserAsync(user.Pk); EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}")); } Delay(); //Учет задержки continue; } } Thread.Sleep(1000); } catch (Exception e) { EventFromMyClass(this, new MyEventMessage( $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] ОШИБКА: {e.Message}")); } } } EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{ DateTime.Now.ToString("HH:mm:ss")}] Выполнено.")); EventUpdateGrid(this, new UpdateGridEvent( $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" + $"Завершено")); Stat = false; }
/// <summary> /// Get All the follower list of logged in user /// </summary> /// <returns>The follower list</returns> public async Task <IResult <InstaUserShortList> > GetFollowers() { IResult <InstaUserShortList> followers = await api.GetUserFollowersAsync(user.UserName, PaginationParameters.Empty); return(followers); }
private static void Main(string[] args) { // create user session data and provide login details var userSession = new UserSessionData { UserName = "******", Password = "******" }; // create new InstaApi instance using Builder _instaApi = new InstaApiBuilder() .SetUser(userSession) .Build(); // login var logInResult = _instaApi.Login(); if (!logInResult.Succeeded) { Console.WriteLine($"Unable to login: {logInResult.Message}"); } else { // get currently logged in user var currentUser = _instaApi.GetCurrentUser().Value; Console.WriteLine($"Logged in: username - {currentUser.UserName}, full name - {currentUser.FullName}"); // get followers var followers = _instaApi.GetUserFollowersAsync(currentUser.UserName, 5).Result.Value; Console.WriteLine($"Count of followers [{currentUser.UserName}]:{followers.Count}"); // get user's media var currentUserMedia = _instaApi.GetUserMedia(currentUser.UserName, 5); if (currentUserMedia.Succeeded) { Console.WriteLine($"Media count [{currentUser.UserName}]: {currentUserMedia.Value.Count}"); foreach (var media in currentUserMedia.Value) { Console.WriteLine($"Media [{currentUser.UserName}]: {media.Caption.Text}, {media.Code}, likes: {media.LikesCount}, image link: {media.Images.LastOrDefault()?.Url}"); } } //get user feed, first 5 pages var userFeed = _instaApi.GetUserFeed(5); if (userFeed.Succeeded) { Console.WriteLine($"Feed items (in {userFeed.Value.Pages} pages) [{currentUser.UserName}]: {userFeed.Value.Items.Count}"); foreach (var media in userFeed.Value.Items) { Console.WriteLine($"Feed item - code:{media.Code}, likes: {media.LikesCount}"); } } // get tag feed, first 5 pages var tagFeed = _instaApi.GetTagFeed("gm", 5); if (userFeed.Succeeded) { Console.WriteLine($"Tag feed items (in {tagFeed.Value.Pages} pages) [{currentUser.UserName}]: {tagFeed.Value.Count}"); foreach (var media in tagFeed.Value) { Console.WriteLine($"Tag feed item - code: {media.Code}, likes: {media.LikesCount}"); } } var logoutResult = _instaApi.Logout(); if (logoutResult.Value) { Console.WriteLine("Logout succeed"); } } Console.ReadKey(); }