get photo set by id and then bind

Topics: Developer Forum
Jul 26, 2011 at 1:58 PM

I am new to this api but have a simple request that I cannot seem to work out.

I want to retrieve a photoset by id and display it on a page by binding it to a datalist and eventually enable paging.

The below page _load code will not work for me and I was hoping someone could lead me in the right direction.

 

string flickrKey = "keyhere";
        string sharedSecret = "secretehere";
        string setid = "setidhere";

        Flickr flickr = new Flickr(flickrKey, sharedSecret);

        Photoset set = new Photoset();
        set.PhotosetId = setid;

        ThumbnailsList.DataSource = set;
        ThumbnailsList.DataBind();

Coordinator
Jul 26, 2011 at 2:01 PM

You actually need to call Flickr to get the photoset details:

Photoset set = flickr.PhotosetGetInfo(setid);

or something similar.

Sam

Jul 26, 2011 at 2:17 PM

Thank you, small issues like this are the biggest problems for me.

I changed the code as you specified  and I am getting an error: An invalid data source is being used for ThumbnailsList. A valid data source must implement either IListSource or IEnumerable.

Do I need to specify additional settings than maybe I am unaware of being this is new for me?

 

 

Flickr flickr = new Flickr(flickrKey, sharedSecret);

        Photoset set = flickr.PhotosetsGetInfo(setid);

        ThumbnailsList.DataSource = set;
        ThumbnailsList.DataBind();

Coordinator
Jul 26, 2011 at 2:29 PM

Well if you are (I'm only guessing here) actually wanting to show the photos in the photoset, then perhaps you should be calling PhotosetsGetPhotos(setid) instead.

Sam

Jul 26, 2011 at 3:28 PM

Thank you - I got it to work with the following code but need to know how to increase the image size from SquareThumbnailUrl to something larger.Is there a doc on what sizes that flickr returns?

Flickr flickr = new Flickr(flickrKey, sharedSecret);

PhotosetPhotoCollection set = flickr.PhotosetsGetPhotos(setid);
ThumbnailsList.DataSource = set;
ThumbnailsList.DataBind();

Coordinator
Jul 26, 2011 at 3:40 PM

The following link lists the different sizes, or you can just look at a photo on Flickr:

http://www.flickr.com/services/api/misc.urls.html

You can get these sizes returned by passing in the PhotoSearchExtras property to the PhotosetsGetPhotos method.

Sam

Jul 26, 2011 at 5:04 PM

that worked perfect I really appreciate all this help!  I now want to enable paging and have 5 per page.  Do you know of any good examples that show the code for paging?

I also do not know the correct way to add options to the display after declaring the set and the below code does not work.

PhotoSearchOptions options = new PhotoSearchOptions();
        options.PerPage = 12;
        options.Page = 1;
        options.SortOrder = PhotoSearchSortOrder.DatePostedDescending;

PhotosetPhotoCollection set = flickr.PhotosetsGetPhotos(setid,options);

Coordinator
Jul 26, 2011 at 5:11 PM

Well you've got the code for paging right there, you just need to track the options.Page property and map that to the properties.

Adding extras is done like this:

options.Extras |= PhotoSearchExtras.SmallUrl; // or AllUrls for all urls

Sam

Jul 26, 2011 at 5:59 PM

this is where I am showing my inexperience because I am unsure what comes first and how to apply the options to the set.

I thought I first would declare the options and then declare the set but how do I make both work together?

I had the thought it might be flickr.PhotosetsGetPhotos(setid,options); but that did not work so I must be very close but going the wrong way.

 Flickr flickr = new Flickr(flickrKey, sharedSecret);

        PhotoSearchOptions options = new PhotoSearchOptions();
        options.PerPage = 5;
        options.Page = 1;
        options.SortOrder = PhotoSearchSortOrder.DatePostedDescending;

        PhotosetPhotoCollection set = flickr.PhotosetsGetPhotos(setid); //

        ThumbnailsList.DataSource = set;
        ThumbnailsList.DataBind();

Coordinator
Jul 26, 2011 at 7:50 PM

Yes, my mistake. PhotoSearchOptions is only used with the PhotosSearch method.

For PhotosetsGetPhotos just pass the Extras, Page and PerPage parameters in.

PhotosetCollection set = flickr.PhotosetsGetPhotos(setId, PhotoSearchExtras.AllUrls, 1, 5);

Sam

Jul 27, 2011 at 1:30 PM

that got it working, thanks.  If I want to further add things like sort order is that possible?  If so do I have to declare flickr again and set options?  any help is appreciated.

Coordinator
Jul 27, 2011 at 1:34 PM

You can't sort the results of PhotosetsGetPhotos - you're stuck with the order they are in the photoset.

The only searches that can be sorted are those to PhotosSearch method.

Sam

Jul 27, 2011 at 1:51 PM

can I still perform paging using the photoset method?

Is it possible to find total pages returned and total images returned using the photoset method?

Thank you

Mike

Coordinator
Jul 27, 2011 at 2:02 PM

I feel like I'm answering questions here that could be answered by yourself if you took some time to study the Flickr API on the API pages here:

http://www.flickr.com/services/api

Use the API explorer found at the bottom of each method description page to test the api and you'll see all the parameters you can pass in and examples of the responses you get back.

If you can see it in the API explorer, then you'll find a corresponding parameter or property in the Flickr.Net library.

In the case of page count you'd want the PhotosetPhotoCollection properties, Page, Pages, PerPage and Total. Count will contain the number of actual photos return for that page.

Sam

Nov 21, 2011 at 8:07 PM

I am trying to do the same thing but with the silverlight library.  the PhotosetsGetPhotos method doesn't seem to be available.

Flickr flickr = new Flickr(a,b);

PhotosetPhotoCollection wwpwImages = flickr.PhotosetsGetPhotos(setId);

Should I be doing something different or did that method get replaced?

Thanks,

Alex

Coordinator
Nov 22, 2011 at 9:53 AM

If you are using the Silverlight library then everything has to be Async, so you need to use the PhotosetsGetPhotosAsync(photosetid, callback) method instead.

Sam

Nov 22, 2011 at 2:08 PM
samjudson wrote:

If you are using the Silverlight library then everything has to be Async, so you need to use the PhotosetsGetPhotosAsync(photosetid, callback) method instead.

Sam

What exactly is the method callback?  The overload documentation say its a System.Action<FlickrResult<PhotosetPhotoCollection>>callback.  Do I need to instantiate something special to hold the callback?

Coordinator
Nov 22, 2011 at 2:25 PM

It is basically a method delegate that takes a FlickrResult parameter. This is either done using lamdas or methods (just like you do with events).

 

f.PhotosetsGetPhotos(setid, r =>
{
   if( r.HasError )
      Console.WriteLine("Error : " + r.Error.Message;
   else
   {
      PhotosetPhotoCollection col = r.Results;
      // Do something with photos here.
   }
});

 

or

 

f.PhotosetsGetPhotos(setid, PhotosetsGetPhotos_Complete);


function PhotosetsGetPhotos_Complete(FlickrResult<PhotosetsPhotoCollection> r)
{
   if( r.HasError )
      Console.WriteLine("Error : " + r.Error.Message;
   else
   {
      PhotosetPhotoCollection col = r.Results;
      // Do something with photos here.
   }
}

 

 

Nov 22, 2011 at 2:31 PM

Great thanks!