public async Task DoShow() { // search for related locations near location with latitude = 55.753923, logitude = 37.620940 // additionaly you can specify search query or just empty string var result = await _instaApi.SearchLocation(55.753923, 37.620940, "square"); Console.WriteLine($"Loaded {result.Value.Count} locations"); var firstLocation = result.Value?.FirstOrDefault(); if (firstLocation == null) { return; } Console.WriteLine($"Loading feed for location: name={firstLocation.Name}; id={firstLocation.ExternalId}."); var locationFeed = await _instaApi.GetLocationFeed(long.Parse(firstLocation.ExternalId), PaginationParameters.MaxPagesToLoad(5)); Console.WriteLine(locationFeed.Succeeded ? $"Loaded {locationFeed.Value.Medias?.Count} medias for location, total location medias: {locationFeed.Value.MediaCount}" : $"Unable to load location '{firstLocation.Name}' feed"); }
private async Task DownloadLocationMediaAsync(string input, int downloadLimit) { var downloadCount = 0; var downloadFolder = _mediaFilter.CustomFolder ? $@"{_downloadFolder}\{input}" : _downloadFolder; var statsFile = $@"{_statsDirectory}\{input}.csv"; if (!File.Exists(statsFile)) { using (var csv = new Csv(statsFile, _delimiter)) { csv.WriteHeader(); } } var maxId = ""; do { var locationMedia = await _instaApi.GetLocationFeed(long.Parse(input), PaginationParameters.MaxPagesToLoad(1).StartFromId(maxId)); if (!locationMedia.Succeeded) { return; } maxId = locationMedia.Value.NextId; if (!_mediaFilter.SkipTopPosts) { foreach (var rankedMedia in locationMedia.Value.RankedMedias) { _cancellationToken.ThrowIfCancellationRequested(); if (_mediaFilter.CheckFilters(rankedMedia)) { continue; } if (CheckTotalDownloads() && CheckDownloadLimit(downloadCount++, downloadLimit)) { await DownloadInstaMediaAsync(rankedMedia, statsFile, downloadFolder); } else { return; } } } foreach (var media in locationMedia.Value.Medias) { _cancellationToken.ThrowIfCancellationRequested(); if (_mediaFilter.CheckFilters(media)) { continue; } if (CheckTotalDownloads() && CheckDownloadLimit(downloadCount++, downloadLimit)) { await DownloadInstaMediaAsync(media, statsFile, downloadFolder); } else { return; } } } while (maxId != null); }