2013-02-16 129 views
1

我试图获得响应图像的网址,所以我可以将它作为背景附加。它的作品,但它为每一个附加相同的图像。这是我的代码:Facebook相册图片网址

getUserAlbums : function(){ 
    FB.api('/me/?fields=id,name,albums', function(response) { 
     var albums = response.albums.data; 
     var frame = ""; 
     console.log(albums); 
     _.each(albums, function(album) { 

      FB.api('/'+album.cover_photo+"/picture?type=album", function(response) { 
       var url = response.data; 
       _.each(url, function(bg) { 
        console.log(url); 
        $("li.album").css({backgroundImage:"url("+bg.replace("_s.jpg", "_a.jpg")+")"}); 
       }); 
      }); 

      frame += '<li class="album"><img src="images/fb_frame.png"/></li>'; 

      $('ul#albums').append(frame); 

     }); 

    }); 
} 

即时通讯使用下划线btw这是什么“_.each”是。 这里真正的问题是,当附加照片时,它显示每张专辑的相同照片,这意味着我的循环被覆盖,但我不明白为什么。

回答

0

我想通了,我不得不改变我在我的附加数据的方式:你不需要更换_s.jpg到a_jpg

FB.api('me/?fields=albums', function(response) { 
     var albums = response.albums.data; 
     _.each(albums, function(album, i) { 
      FB.api('/'+album.cover_photo+"/picture?type=album", function(res) { 
       var frame = $('<li class="album"><img src="images/fb_frame.png"/></li>').appendTo('ul#albums'); 
       frame.css({backgroundImage:'url('+res.data.url.replace('_s.jpg', '_a.jpg')+')'}); 
      }); 
     }); 
    }); 
0

。检出照片对象的图像字段。从这里你可以选择图片。

me/?fields=id,name,albums.fields(photos.fields(images)) 

"albums": { 
    "data": [ 
     { 
     "id": "xxxxxx", 
     "created_time": "2011-04-01T03:17:15+0000", 
     "photos": { 
      "data": [ 
      { 
       "images": [ 
       { 
        "height": 1107, 
        "width": 2048, 
        "source": "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-prn1/s2048x2048/xxxx_n.jpg" 
       }, 
       { 
        "height": 330, 
        "width": 610, 
        "source": "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-prn1/XXXX_n.jpg" 
       }, 
       { 
        "height": 330, 
        "width": 610, 
        "source": "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-prn1/xxxxx_n.jpg" 
       }, 
       { 
        "height": 324, 
        "width": 600, 
        "source": "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-prn1/s600x600/xxxxxxxxx_n.jpg" 
       }, 
       { 
        "height": 259, 
        "width": 480, 
        "source": "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-prn1/s480x480/xxxxxxxx_n.jpg" 
       }, 
       { 
        "height": 173, 
        "width": 320, 
        "source": "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-prn1/s320x320/xxxxxxx_n.jpg" 
       }, 
       { 
        "height": 97, 
        "width": 180, 
        "source": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-prn1/xxxxxx_a.jpg" 
       }, 
       { 
        "height": 70, 
        "width": 130, 
        "source": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-prn1/xxxxxxxx_s.jpg" 
       }, 
       { 
        "height": 70, 
        "width": 130, 
        "source": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-prn1/s75x225/xxxxxx_s.jpg" 
       } 
       ], 
       "id": "4274066575883", 
       "created_time": "2013-02-09T10:43:54+0000" 
      }, 
相关问题