2011-03-11 17 views
30

यह काफी आम होना चाहिए लेकिन किसी भी तरह से मैं इसे काम नहीं कर सकता। मैं फेसबुक से एल्बम एल्बम प्राप्त करना चाहता हूं। मैं इसे वेबसाइट पर कार्यान्वित कर रहा हूं।फेसबुक एपीआई का उपयोग करके एल्बम चित्र कैसे प्राप्त करूं?

function getAlbumPhotos(){ 
      FB.api('/me/albums', function(resp) { 
       //Log.info('Albums', resp); 
       var ul = document.getElementById('albums'); 
       for (var i=0, l=resp.data.length; i<l; i++){ 
        var 
         album = resp.data[i], 
         li = document.createElement('li'), 
         a = document.createElement('a'); 
        a.innerHTML = album.name; 
        a.href = album.link; 
        li.appendChild(a); 
        ul.appendChild(li); 
       } 
      }); 
     }; 

resp एक डेटा सरणी जो फोटो एलबम के लिए लिंक शामिल रिटर्न लेकिन मैं प्रत्येक एल्बम के लिए छवि सूत्रों चाहते हैं और मैं कुछ भी नहीं दिख रहा है:

मैं इस कोड का उपयोग एलबम प्राप्त कर सकते हैं मैं resp डेटा में उपयोग कर सकते हैं। डेटा ऑब्जेक्ट में एल्बम का लिंक होता है लेकिन व्यक्तिगत छवियां नहीं होती हैं।

फेसबुक प्रलेखन के अनुसार, एल्बम एल्बमों के लिए "कनेक्शन" हैं। मुझे यकीन नहीं है कि इसका क्या मतलब है लेकिन उनके डॉक्टर से पता चलता है कि आप व्यक्तिगत तस्वीरें प्राप्त कर सकते हैं।

इस लिंक से: (?)

[http://developers.facebook.com/docs/reference/api/album/][1] 

यह json से पता चलता लिंक, आईडी, नाम, आदि ... जो मैं कर रहा हूँ वापस आती है। हालांकि, उस पृष्ठ के निचले हिस्से में एल्बम के लिए "कनेक्शन" हैं जिनमें फ़ोटो, टिप्पणियां, चित्र शामिल हैं। जब मैं फ़ोटो पर क्लिक करता हूं, तो यह JSON डेटा संरचना को img src सहित दिखाता है। सवाल यह है कि, मैं इसे कैसे प्राप्त करूं? यह बहुत सरल लगता है लेकिन मैं इसे काम नहीं कर सकता।

मैंने कोशिश की

FB.api('/me/photos',function(resp) ... 

और

FB.api('/me/photo',function(resp) ... 

तस्वीरें लौट कुछ भी नहीं है, जबकि तस्वीर रिटर्न अपरिभाषित।

कोड नमूने की सराहना की जाएगी।

उत्तर

47
  1. पहले से आप सभी एलबम (और एल्बम आईडी) आप एल्बम तस्वीर मिल सकती है वहाँ से '/me/albums'
  2. (कवर) '/'+album.id+'/picture'
  3. और एल्बम के द्वारा लोगों के फोन '/'+album.id+'/photos'
+1

धन्यवाद। सही काम करता है। – okysabeni

2
FB.api("/"+albumid+"/photos",function(response){ 
    var photos = response["data"]; 
    document.getElementById("photos_header").innerHTML = "Photos("+photos.length+")"; 
    for(var v=0;v<photos.length;v++) { 
     var image_arr = photos[v]["images"]; 

     var subImages_text1 = "Photo "+(v+1); 

     //this is for the small picture that comes in the second column 
     var subImages_text2 = '<img src="'+image_arr[(image_arr.length-1)]["source"]+'" />'; 

     //this is for the third column, which holds the links other size versions of a picture 
     var subImages_text3 = ""; 

     //gets all the different sizes available for a given image 
     for(var j = 0 ;j<image_arr.length;j++) { 
      subImages_text3 += '<a target="_blank" href="'+image_arr[j]["source"]+'">Photo('+image_arr[j]["width"]+"X"+image_arr[j]["height"]+')</a><br/>'; 
     } 
     addNewRow(subImages_text1,subImages_text2,subImages_text3); 
    } 
}); 
1
 <script src="http://connect.facebook.net/en_US/all.js"></script> 

     <script type="text/javascript"> 
      var loggedIn = false;   

      function loginFacebook() 
      { 
       //initializes the facebook API 
      }   




      function loadAlbums() 
      {    
       FB.init({ 
      appId : '345203265493024', 
      status : true, // check login status 
      cookie : true, // enable cookies to allow the server to access the session 
      xfbml : true // parse XFBML 
       }); 





FB.login(function(response) 
{ 
if (response.authResponse) 
{ 

//Logged in and accepted permissions! 

     document.getElementById("status").innerHTML = "Getting album information from your Facebook profile"; 
       var counter = 0; 

     // Start Normal API 
       FB.api('/me/albums', function(response) 
       { 


        var d=response.data; 



        for (var i=0, l=d.length; i<l; i++) 
        { 
         addOption(response["data"][i].name,response["data"][i].id); 
         counter++; 


        } 
        document.getElementById("status").innerHTML = "There are "+ counter +" albums in your Facebook profile"; 
       }); 


       //end of Normal API 

     document.getElementById("albumBtn").style.visibility="hidden"; 



} 
},{scope:'read_stream,publish_stream,offline_access,user_photos,friends_photos,user_photo_video_tags,friends_photo_video_tags'}); 


      } 

      //Adds a new option into the drop down box 
      function addOption(opText,opVal) 
      { 
       var v = document.getElementById("albumsList");    
       v.innerHTML += '<br/><a href="facebookphotos.aspx?album='+opVal+'&name='+opText+'">'+opText+'</a>';    
      } 

      function init() 
      { 
       var v1 = document.getElementById("albumBtn"); 
       v1.onclick = loadAlbums; 
       // v1.style.visibility= "hidden";    
      } 

      //calls init function once all the resources are loaded 
      window.addEventListener("load",init,true); 
     </script>  


this code works 
+3

एसओ में आपका स्वागत है। कृपया कोड पोस्ट करते समय उचित स्वरूपण का उपयोग करें। –

+0

मुझे नहीं पता कि यह कोड ब्रेसिज़ के रूप में कैसे काम करेगा ('{' और '}') शेष नहीं है। आप यहाँ कुछ खो रहे हैं। –

3

आप भी

कोशिश कर सकते हैं 63,210

/_ABLUM_ID_/तस्वीरें

ग्राफ एपीआई पर

, अर्थात

https://graph.facebook.com/12341234/photos

जहां 12,341,234 एल्बम आप की फोटो प्राप्त करना चाहते हैं की एलबम ऑब्जेक्ट id है।

1

आप इस API का उपयोग कर सकते हैं:? मुझे/'

$ तस्वीरें = $ फेसबुक> एपीआई (खेतों = albums.limit (50) .fields (photos.limit (50) .fields (आईडी, स्रोत)) ');

संबंधित मुद्दे