3

This code works perfectly:

$f = new phpFlickr(FLICKR_API_KEY, FLICKR_API_SECRET);
$f->setToken(FLICKR_AUTH_TOKEN);
// Next line is just WordPress providing the photoset ID.
$mySetID = get_post_meta($post->ID, 'Flickr set ID', true); 
$mySet = $f->photosets_getPhotos($mySetID, NULL, NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
    echo '<div><img src="'. $f->buildPhotoURL($photo, 'large') .'" alt="" /></div>';
}

...until buildPhotoURL is told to fetch the "original" size, at which point the URL returned is something like "http://farm6.static.flickr.com/5607/5332878962__o." which is obviously not valid.

While everything I've found through searches seems to agree that doing this requires some "originalsecret" and "originalformat" values that are barely mentioned in Flickr's own documentation, and phpFlickr does seem to try and use them, they're clearly not being fetched by default and I've yet to see someone post code for how to actually provide them. I've tried calling $f->photos_getInfo() just before the echo line, passing in various things to no effect and I'm starting to feel like I'm missing something everyone thinks is obvious, even though nobody has ever produced a valid response(that I can find) to repeated questions about it on the phpFlickr forum.

Note:

  • This is a Pro account.
  • We are authenticating properly(these are private sets and they work fine for all other sizes).
  • Access to the original size in Flickr's privacy settings is set to "Anyone."

Ideas?

Su'
  • 2,128
  • 20
  • 22
  • You say at the beginning that this code works perfectly. And the explanation isn't quite clear. Can you be more specific as to what you need help with? The image URL should be in this format to be able to access/display it `http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{o-secret}_o.(jpg|gif|png)` – Nishant Nov 25 '11 at 18:16

2 Answers2

4

I know it's a little late and I'm sure you've figured out the problem by now, but I wanted to share a related answer, because I just spent some time wrestling with a similar issue, and as you said, answers on this subject can't be found anywhere.

To get the information needed to display original size images from a set, the following url should work:

http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=YOURAPIKEYNUMBER&photoset_id=YOURSETIDNUMBER&per_page=100&sort=date-posted-desc&extras=original_format&format=json&jsoncallback=?

Of course all of the variables are customizable to your needs, but that's just one example which shows the first 100 images in a set sorted descending by date with the original image formatting information attached including the important "original" secret code

To display the images the javascript you can use is

'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.originalsecret + '_' + 'o' + '.' + item.originalformat;

The main sticking point is "&extras=original_format" because that gives you both the originalsecret and originalformat which you need to call an original size image from flickr. I was using the SuperSized background plugin when I ran into the original size problem.

Jess
  • 496
  • 5
  • 10
  • Thanks. This also helped for the [Flickr4Java](https://github.com/callmeal/Flickr4Java) framework using the SearchParameters.setExtras()-method with a set that contains "original_format". – binwiederhier Jul 31 '13 at 00:14
3

The photosets_getPhotos() method doesn't return the full array for $photo. It returns some basic info about $photo but not $photo['originalformat'], which is needed by buildPhotoURL().

You can tell photosets_getPhotos() to return the original format as an optional extra. This gives buildPhotoURL() everything it needs.

Example:

$mySet = $f->photosets_getPhotos($mySetID, 'original_format', NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
    echo '<div><img src="'. $f->buildPhotoURL($photo, 'original') .'" alt="" /></div>';
}

Even better, you can have photosets_getPhotos() return the URL for the original photo itself.

Example:

$mySet = $f->photosets_getPhotos($mySetID, 'url_o', NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
    echo '<div><img src="'. $photo['url_o'] .'" alt="" /></div>';
}
Elias Ranz
  • 401
  • 1
  • 6
  • 21
Brett DeWoody
  • 59,771
  • 29
  • 135
  • 184
  • I am using 'phpflickr' for dealing with Flickr API. And its use curl. I have checked the request and it has 'extras', but neither 'url_o' nor 'original_format' (I checked these 2) coming in response. any suggestions? – Sadee Mar 13 '15 at 16:12