2017-05-11 40 views
0

我需要用鏈接包裝從這個請求輸出的圖像,我的API知識是有限的,所以不幸我碰到了牆壁。Javascript - 用鏈接包裝我的Flickr Api圖像請求

這是我目前的功能,它輸出相冊中的圖像。請參閱小提琴的工作版本。

var endpoint = "https://api.flickr.com/services/rest/" 
    var apiKey = "e3e0e77b3f6aa14bc816b1e6855f70b7"; 
    var photosetId = "72157682947882356"; 
    var extras = "url_sq,url_t,url_s,url_m,url_o"; 
    var method = "flickr.photosets.getPhotos"; 

    var request = endpoint+"?method="+method+ 
       "&api_key="+apiKey+ 
       "&photoset_id="+photosetId+ 
       "&extras="+extras+ 
       "&format=json&jsoncallback=?"; 
    $.getJSON(request,buildGallery); 

    function buildGallery(data,result){ 
     if(result=="success"){ 
      var photos = data.photoset.photo; 
      for(var i=0; i<photos.length; i++){ 
       $('<img class="gallery_image" >').attr("src",photos[i].url_m).appendTo(".flicker"); 

      } 
     } 

    } 

https://jsfiddle.net/samwsmith/88834z4f/

感謝您的時間。

回答

0

我設法解決這個問題,並將這個.wrap("<a href='" + photos[i].url_o + "'> </a>");添加到我的buildGallery函數中。

var endpoint = "https://api.flickr.com/services/rest/" 
    var apiKey = "e3e0e77b3f6aa14bc816b1e6855f70b7"; 
    var photosetId = "72157682947882356"; 
    var extras = "url_sq,url_t,url_s,url_m,url_o"; 
    var method = "flickr.photosets.getPhotos"; 

    var request = endpoint+"?method="+method+ 
       "&api_key="+apiKey+ 
       "&photoset_id="+photosetId+ 
       "&extras="+extras+ 
       "&format=json&jsoncallback=?"; 
    $.getJSON(request,buildGallery); 

    function buildGallery(data,result){ 
     if(result=="success"){ 
      var photos = data.photoset.photo; 
      for(var i=0; i<photos.length; i++){ 
       $('<img class="gallery_image" >').attr("src",photos[i].url_m).appendTo(".flicker").wrap("<a href='" + photos[i].url_o + "'> </a>"); 


      } 
     } 

    } 

更新小提琴:https://jsfiddle.net/samwsmith/88834z4f/ 我希望這有助於同樣的問題的人。