private static async void RunCommentTaskAsync(TaskModel t, IInstaApi api) { List <InstaMedia> medias = new List <InstaMedia>(); foreach (var search in t.Searches) { if (search.InUsers) { var _tempList = new List <InstaUserShort>(); foreach (var inString in search.GetInStrings()) { var _temp = await api.SearchUsersAsync(inString); if (_temp.Succeeded) { _tempList.AddRange(_temp.Value); } } _tempList = await Helper.GetFilteredUsersAsync(_tempList, t.Searches, api, 10); foreach (var user in _tempList) { var _userMedia = await api.GetUserMediaAsync(user.UserName, PaginationParameters.MaxPagesToLoad(5)); if (_userMedia.Succeeded) { medias.AddRange(_userMedia.Value); } } } if (search.InPosts) { var _temp = await api.GetUserTimelineFeedAsync(PaginationParameters.MaxPagesToLoad(5)); if (_temp.Succeeded) { medias.AddRange(_temp.Value.Medias.ToList()); } } var filteredMedia = await Helper.GetFilteredMediaAsync(medias, t.Searches, api, 5); foreach (var media in filteredMedia) { var result = await api.CommentMediaAsync(media.InstaIdentifier, await Helper.ConstructCaptionTextAsync(t.GetValues().Text, t.Searches, api)); if (result.Succeeded) { t.TaskExecuted(); Helper.Log($"Task Executed: {t.Name} - {t.TaskType.ToString()} {Environment.NewLine} {JsonConvert.SerializeObject(result.Value)}"); } else { Helper.Log(JsonConvert.SerializeObject(result.Info)); } } } }
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 self followers var followers = await _instaApi.GetUserFollowersAsync(currentUser.Value.UserName, 5); Console.WriteLine($"Count of followers [{currentUser.Value.UserName}]:{followers.Value.Count}"); // get self folling var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, 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, 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(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", 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); } } }
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); } } }