2013-05-01 60 views
0

我對我的網站的Facebook API非常陌生,我使用javascript sdk。我想獲得用戶最新的學校信息,包括學校名稱,課程和學習年份。這是我迄今爲止,但它打破登錄腳本,並返回'response.education.school是未定義'。我猜測我需要某種形式的循環才能通過教育陣列,因爲大多數用戶都有不止一所學校?Facebook API(javascript)獲取最新的學校教育信息

function login() { 
    FB.login(function(response) { 
     if(response.authResponse) { 
      // connected 
      FB.api('/me', function(response) { 
       fbLogin(response.id, response.name, response.firstname, response.email, 
         response.education.school.name, response.education.concentration.name, response.education.year.name); 
      }); 
     } else { 
      // cancelled 
     } 
    }, {scope: 'email, user_education_history, user_hometown'}); 
} 
+0

你是對的,它的主要陣列。還要確保你有'user_education_history'權限並且添加'fields = education'和'/ me'以確保你獲得了數據。 – 2013-05-02 06:50:40

回答

1

response.education.school未定義

這是因爲responce.education是對象的數組。這將是對我的例子(實際信息已刪除)

"education": [ 
    { 
     "school": { 
     "id": "", 
     "name": "" 
     }, 
     "year": { 
     "id": "", 
     "name": "" 
     }, 
     "concentration": [ 
     { 
      "id": "", 
      "name": "" 
     } 
     ], 
     "type": "" 
    }, 
    ... 
    ] 

您需要遍歷它,例如處理每個educaional一步

for(ed in response.education) { 
    var school = response.education[ed].school; 
    var schoolName = school.name; 
    ... 
} 

等等;您目前正在將一個aobject結構傳遞給您的fbLogIn,無法處理它。如果您想要接受最新的學校教育,您只需選擇具有最新year.name價值的教育。