我对我的网站的facebook api非常陌生,我正在使用javascript sdk。我想获得用户最新的学校信息,包括学校名称,课程,学年。这就是我到目前为止所做的,但它打破了登录脚本并返回'response.education.school is undefined'。我猜我需要某种for循环来遍历教育数组,因为大多数用户都列出了多个学校?
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'});
}
response.education.school is undefined
这是因为responce.education
是一个对象数组。这将是我的一个例子(实际信息删除)
"education": [
{
"school": {
"id": "",
"name": ""
},
"year": {
"id": "",
"name": ""
},
"concentration": [
{
"id": "",
"name": ""
}
],
"type": ""
},
...
]
你需要遍历它并处理每个教育步骤,例如
for(ed in response.education) {
var school = response.education[ed].school;
var schoolName = school.name;
...
}
等等;你目前正在传递一个对象结构给你的fbLogIn
,但它不能处理它。如果你想要最新的学校教育,你只需选择一个有最近的year.name
值。