How do I get phpFlickr to return the original image?
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 si开发者_运维百科zes).
- Access to the original size in Flickr's privacy settings is set to "Anyone."
Ideas?
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.
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>';
}
精彩评论