加载一个随机flickr图像&附加到div [英] Load one random flickr image & append to div

查看:109
本文介绍了加载一个随机flickr图像&附加到div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上试图加载一个从特定用户和特定集合中获取的随机flickr图像,然后在id为flickr-wrap的div中显示。我正在尝试操纵这个JSON代码来做我想要的但是没有线索从哪里开始。此代码目前加载了大量图片(我只想加载一个)并使用标签(但我想要用户和套装),有人可以帮我解决吗?

I'm basically trying to load in one random flickr image taken from a specific user and specific set which then gets displayed within a div with the id of 'flickr-wrap'. I'm trying to manipulate this JSON code to do what I want but haven't a clue where to start. This code currently loads in lots of images (I just want one to load in) and uses tags (but I want user and sets instead), could anyone help me out?

 $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",{
    id: "51997044@N03",
    tagmode: "any", 
    format: "json" },
  function(data) {
    $("<img/>").attr({src: data.items[0].media.m.replace('_m.','.')}).appendTo("#flickr-wrap");
  });

编辑

我已经停止了很好的循环,现在已经更新了上面的代码来提取照片set.gne而不是public.gne,并通过删除一些代码行稍微改变了我在photoset中调用的方式。 现在我需要做的就是从该套装中随机抽取图片。以下是我到目前为止所做的事情:

I've stopped the loop which is great and have now updated the above code to pull in the photo set.gne instead of the public.gne, and have slightly changed how I call in the photoset by removing some lines of code. Now all I need to do is pull in a random image from that set. Here's what ive got so far:

$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=72157626230243906&nsid=51997044@N03&lang=en-us&format=json&jsoncallback=?",
  function(data) {
    $("<img/>").attr({src: data.items[0].media.m.replace('_m.','.')}).appendTo("#flickr-wrap");
  });

编辑

还没有得到随机的工作呢。最烦人的。真的可以在这里使用一些帮助。绝望!

Still haven't got the random thing to work yet. Most annoying. Could really use some help here. Desperate!

推荐答案

最后,我不得不采取完全不同的方法。事实证明Flickr徽章API已更改,并且在我试图找出此问题的答案时增加了更大的灵活性。它基本上完成了我现在需要的工作: http://www.flickr.com/badge.gne

In the end I had to take a completely different approach. Turns out the Flickr badge API changed and added more flexibility whilst I was trying to figure out the answer to this question. It basically does what I need to now: http://www.flickr.com/badge.gne

这篇关于加载一个随机flickr图像&amp;附加到div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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