public void IsCommonsMultiplePages()
        {
            var options = new PhotoSearchOptions
            {
                IsCommons = true,
                Text      = "photochrom",
                SortOrder = PhotoSearchSortOrder.DatePostedDescending,
                PerPage   = 10,
                Page      = 1,
                Extras    = PhotoSearchExtras.DateUploaded
            };

            var allPhotos = new PhotoCollection();

            for (var i = 0; i < 10; i++)
            {
                options.Page = i + 1;
                var photos = Instance.PhotosSearch(options);
                var ids    = photos.Select(p => p.PhotoId).ToArray();
                var photo  = allPhotos.FirstOrDefault(p => ids.Contains(p.PhotoId));

                if (photo != null)
                {
                    Assert.Fail("Duplicate photo {0} found on page {1}", photo.PhotoId, i + 1);
                }

                Console.WriteLine(Instance.LastRequest);
                Console.WriteLine(Instance.LastResponse);

                foreach (var p in photos)
                {
                    allPhotos.Add(p);
                }
            }
        }
        public async Task <FlickrNet.Photo> SearchByPhotoId(string photoId, string redisKey)
        {
            try
            {
                var cacheResult = await _redisCache.GetStringAsync(redisKey);

                if (!string.IsNullOrWhiteSpace(cacheResult))
                {
                    PhotoCollection photoCollections = JsonConvert.DeserializeObject <PhotoCollection>(cacheResult);
                    return(photoCollections.FirstOrDefault(x => x.PhotoId.Equals(photoId.Trim())));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format(Constants.ErrorMessage, ex.Message));
            }
        }
Ejemplo n.º 3
0
        public string GetThumbnailUrl(string queryString)
        {
            Flickr flickr = new Flickr(_config["FlickrApiKey"], _config["FlickrSecret"]);
            {
                var options = new PhotoSearchOptions
                {
                    Text       = queryString,
                    Page       = 1,
                    PerPage    = 1,
                    Extras     = PhotoSearchExtras.SmallUrl,
                    SafeSearch = SafetyLevel.Safe,
                    MediaType  = MediaType.Photos
                };
                PhotoCollection photos = flickr.PhotosSearch(options);
                return(photos.FirstOrDefault().LargeSquareThumbnailUrl);
            }

            // temp in dev to avoid hitting the API...
            //return "https://farm1.staticflickr.com/908/28167626118_f9ed3a67cf_q.png";
        }