如何让 phpFlickr 返回原始图像?

发布于 2024-11-07 01:00:13 字数 1303 浏览 0 评论 0原文

此代码完美运行:

$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>';
}

...直到 buildPhotoURL 被告知获取“原始”大小,此时返回的 URL 类似于“http://farm6.static.flickr.com/5607/5332878962__o”。这显然是无效的。

虽然我通过搜索发现的所有内容似乎都同意这样做需要一些“originalsecret”和“originalformat”值,这些值在 Flickr 自己的文档中几乎没有提及,并且 phpFlickr 似乎确实 尝试使用它们,它们显然没有被获取默认情况下,我还没有看到有人发布代码来了解如何实际提供它们。我尝试在 echo 行之前调用 $f->photos_getInfo() ,传递各种东西但没有效果,我开始觉得我错过了每个人都认为显而易见的东西,即使没有人有 曾经对 phpFlickr 论坛上重复出现的问题做出过有效的回复(我可以找到)。

注意:

  • 专业帐户。
  • 我们正在正确进行身份验证(这些是私人集,它们适用于所有其他尺寸)。
  • Flickr 隐私设置中对原始尺寸的访问权限设置为“任何人”。

有想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖 2024-11-14 01:00:13

我知道现在有点晚了,我相信你现在已经解决了问题,但我想分享一个相关的答案,因为我刚刚花了一些时间来解决类似的问题,正如你所说,关于这个的答案无法在任何地方找到主题。

要获取显示一组图像中的原始尺寸图像所需的信息,应使用以下 url:

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=?

当然,所有变量都可以根据您的需要进行自定义,但这只是一个示例,它显示一组中按日期降序排列的前 100 张图像附加原始图像格式信息,包括重要的“原始”密码

要显示图像,您可以使用的 javascript 是

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

主要症结点是“&extras=original_format”,因为这为您提供了您需要的originalsecret 和originalformat从 flickr 调用原始尺寸的图像。当我遇到原始尺寸问题时,我正在使用 SuperSized 背景插件。

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.

深陷 2024-11-14 01:00:13

photosets_getPhotos() 方法不会返回 $photo 的完整数组。它返回一些有关 $photo 的基本信息,但不返回 $photo['originalformat'] 的信息,这是 buildPhotoURL() 需要的。

您可以告诉 photosets_getPhotos() 返回原始格式作为可选的额外内容。这为 buildPhotoURL() 提供了它所需的一切。

示例:

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

更好的是,您可以让 photosets_getPhotos() 返回原始照片本身的 URL。

示例:

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

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>';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文