FlickrNet API - get the given name from PhotosSearch

I use the FlickrNet C # library, which still proves a massive hit.

However, I have one problem. I can get all the photos for the user ID, but I can’t get the given name to which the particular photo belongs without making another api call. This separate call gives me serious performance issues. It takes 30 seconds to load 40 images on the main page. It will only increase.

I need to get the set name for each photo, since I use an isotope to display images.

I just grab the images from the api and bind them to the repeater.

Here is my code.

WITH#

Flickr f = FlickrManager.GetAuthInstance(); protected void Page_Load(object sender, EventArgs e) { string userID = f.PeopleFindByEmail(" me@yahoo.com ").UserId; PhotoSearchOptions options = new PhotoSearchOptions { UserId = userID, Extras = PhotoSearchExtras.AllUrls | PhotoSearchExtras.Description | PhotoSearchExtras.Tags, SortOrder = PhotoSearchSortOrder.Relevance, }; var photos = f.PhotosSearch(options); rptPhotos.DataSource = photos; rptPhotos.DataBind(); } protected string GetSetNameForImageID(string imageID) { var sets = f.PhotosGetAllContexts(imageID).Sets; return sets[0].Title.ToLower().Replace(" ", "-"); } 

HTML

 <asp:Repeater runat="server" ID="rptPhotos"> <ItemTemplate> <section class="<%# GetSetNameForImageID( Convert.ToString( Eval("PhotoID") ) ) %> item"> <%--<a href="@Url.Action("Image", "Home", new {id = item.PhotoId})">--%> <a href="/View.aspx?pid=<%# DataBinder.Eval(Container.DataItem, "PhotoID") %>"> <div> <div class="item_hover"> <header> <span>D</span> <%--<p title="@item.Description" class="tiptip">_</p> --%> <p title="<%# DataBinder.Eval(Container.DataItem, "Description") %>" class="tiptip">_</p> <hgroup> <%--<h2>@item.Title</h2> <h3>@item.Tags[0]</h3>--%> <h2><%# DataBinder.Eval(Container.DataItem, "Title") %></h2> <h3><%# DataBinder.Eval(Container.DataItem, "Tags[0]") %></h3> </hgroup> </header> </div> <%--<img src="@item.Small320Url" alt="Video sit amet consectetur" />--%> <img src="<%# DataBinder.Eval(Container.DataItem, "Small320Url") %>" alt="Video sit amet consectetur" /> </div> </a> </section> </ItemTemplate> </asp:Repeater> 

Is there a faster way to get the set name for each image without GetSetNameForImageID and then calling api?

+4
source share
1 answer

One thing I noticed about PhotosGetAllContexts is that the Sets property that you use is a collection of ContextSet objects, which in turn store the PhotoSetId and Title files.

How to combine PhotosetsGetList and PhotosetsGetPhotos methods ? I think you could use these two to avoid the overhead you are currently experiencing with the PhotosGetAllContexts method.

Disclaimer: Unverified code.

 var photoSets = f.PhotosetsGetList(userId); Dictionary<string, List<Photo>> photoSetPhotoMap = new Dictionary<string, List<Photo>>(); foreach (var photoSet in photoSets) { var photoSetPhotos = f.PhotosetsGetPhotos(photoSet.PhotosetId, PhotoSearchExtras.AllUrls | PhotoSearchExtras.Description | PhotoSearchExtras.Tags); photoSetPhotoMap.Add(photoSet.PhotosetId, photoSetPhotos.ToList()); } var photos = from kvp in photoSetPhotoMap from photo in kvp.Value select new { SetTitle = kvp.Key, PhotoId = photo.PhotoId, Description = photo.Description, PhotoTitle = photo.Title, Tags = photo.Tags[0], Small320Url = photo.Small320Url }; rptPhotos.DataSource = photos; rptPhotos.DataBind(); 

I think that the main difficulty that you will encounter in this approach is effective paging - depending on the size of the photo network (you can determine this by the NumberOfPhotos property), most likely you will encounter scenarios where the page is turned off halfway through the photoset.

To solve this problem, I would suggest using the NumberOfPhotos property to calculate the total number of photos, and then using your page size times the page number to find out how many and which PhotoSets you need to complete the request.

+3
source

All Articles