以get照片组的JQuery / Flickr的API问题 [英] JQuery / Flickr API issue with get Photo set

查看:115
本文介绍了以get照片组的JQuery / Flickr的API问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图拼凑albumn系统中的照片,它通过Flickr的管理,我已经花了近一天左右的Flickr的API玩耍,并具有以下code,但它只是不返回预期的HTML。 insetad我得到一个错误在我的浏览器上面的行($('#图像)HTML(theHtml);)

 <脚本类型=文/ JavaScript的>
     $(文件)。就绪(函数(){   $.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxx&photoset_id=xxxxxxxxxxxxxxxxxxxx=&format=json&jsoncallback=?', displayImages);   功能displayImages(数据){    变种photosetID =;
    VAR标题=;
    变种theHtml =;
    $。每个(data.photosets.photoset,功能(我设置){     photosetID = set.id;
     标题= set.title._content;
     ids.push(photosetID);
     titles.push(职称);     变种sourceSquare =(set.media.m).replace(_ m.jp G,_s.jp G);     theHtml + ='<立GT;< A HREF =+ set.link +'目标=_空白>';
     theHtml + ='< IMG标题=+ set.title +'SRC =+ sourceSquare +'ALT =+ set.title +'/>';
     theHtml + ='< / A>< /李>';
    });    $('#图像)HTML(theHtml); }); });  < / SCRIPT>

使用这样的事情我也看到了例子:

<$p$p><$c$c>$.getJSON(\"http://api.flickr.com/services/feeds/groups_pool.gne?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lang=en-us&format=json&jsoncallback=?\", displayImages);

但不知道确切组ID是什么,是一样的集ID? Flickr的是如何知道我的例子两个谁,因为我没有看到传递任何API。

我的preference将获得第一个例子中的工作,因为这是我一直在努力,但任何意见/例子是apprieciated

欢呼声


解决方案

这是因为你试图使用API​​饲料就好像它是一个RSS feed。它们是两个不同的格式。看看Flickr的API浏览器 photosets.getPhotos

这code应该让你去:

  $。的getJSON(URL,功能(数据){
    $。每个(data.photoset.photo,功能(I,项目){
    VAR squareUrl =的http://农场'+ item.farm +'.static.flickr.com /+ item.server +/+ item.id +'_'+ item.secret +'_s.jpg ;
    VAR largeUrl = squareUrl.replace('_ s.jpg','_b.jpg');
});

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);

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

cheers

解决方案

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

这篇关于以get照片组的JQuery / Flickr的API问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆