问题描述
我一直在尝试组合一个通过 Flickr 管理的相册系统,过去一天左右我一直在玩 Flickr API 并有以下代码,但它只是没有返回预期HTML.insetad 我在浏览器中收到上面一行的错误 ($('#images').html(theHtml);)
I have been trying to put together a photo albumn system that is managed via Flickr, I have been spending the past day or so playing around with the Flickr API and have the following code, but it just doesn't return the expected HTML. insetad I get an error in my browser for the line above ($('#images').html(theHtml);)
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxx&photoset_id=xxxxxxxxxxxxxxxxxxxx=&format=json&jsoncallback=?', displayImages);
function displayImages(data) {
var photosetID = "";
var title = "";
var theHtml = "";
$.each(data.photosets.photoset, function(i,set){
photosetID = set.id;
title = set.title._content;
ids.push(photosetID);
titles.push(title);
var sourceSquare = (set.media.m).replace("_m.jp g", "_s.jp g");
theHtml+= '<li><a href="'+set.link+'" target="_blank">';
theHtml+= '<img title="'+set.title+'" src="'+sourceSquare+'" alt="'+set.title+'" />';
theHtml+= '</a></li>';
});
$('#images').html(theHtml); }); });
</script>
我也看到过使用这样的例子:
Also I have seen examples using something like this:
$.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lang=en-us&format=json&jsoncallback=?", displayImages);
但不确定组 ID 到底是什么,它与集合 ID 相同吗?Flickr 如何知道我在示例二中的身份,因为我没有看到任何 API 被传递.
BUt was not sure what exactly a group id is, is that the same as the set ID? How does Flickr know who I am in example two as I don't see any API being passed.
我的偏好是让第一个示例工作,因为这是我一直在研究的内容,但任何建议/示例都会受到赞赏
My preference would be to get the first example working as that is what I have been working on, but any advice/example would be apprieciated
干杯
推荐答案
这是因为您试图将 api 提要用作 rss 提要.它们是两种不同的格式.查看 flickr api 浏览器 photosets.getPhotos
It's because you're trying to use the api feed as if it were an rss feed. they are two different formats. Take a look at the flickr api browser for photosets.getPhotos
此代码应该可以帮助您:
This code should get you going:
$.getJSON(url, function(data) {
$.each(data.photoset.photo, function(i,item){
var squareUrl = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_s.jpg';
var largeUrl = squareUrl.replace('_s.jpg', '_b.jpg');
});
这篇关于获取照片集的 JQuery/Flickr API 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!