我使用這個代碼:如何獲得朋友的姓名
function login() {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me/friends', {
fields: 'id,name'
}, function(response) {
for (element in response) {
console.log(element.name);
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {
'scope': 'user_friends'
});
}
,但我在控制檯中這樣的響應:
Welcome! Fetching your information....
2 undefined
爲什麼?
編輯:
我剛纔編輯上面的代碼:
function login() {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me/friends', {
fields: 'id,name'
}, function(response) {
console.log(response.summary);
console.log(response);
for (element in response.data) {
console.log(element.id);
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {
'scope': 'user_friends'
});
}
,但現在我得到這樣的迴應:
Welcome! Fetching your information....
Object {total_count: 58}
Object {data: Array[0], summary: Object}
是什麼反應? – WizKid
@WizKid剛剛編輯迴應的問題:) – xRobot
的回覆是正確的,沒有你的朋友授權你的應用 – luschn