我正在开发一个网站,用户可以在其中添加他们的 facebook 朋友。通常我会使用 apprequests 但此功能仅适用于 2.3 版以后的游戏。目前我只能使用Graph API 的发送请求功能向朋友发送消息,但我也想检索谁的朋友列表消息已发送。
Javascript SDK 代码..
function importfb(){
FB.login(function(response) {
// handle the response
console.log("Response goes here!");
console.log(JSON.stringify(response));
// check whether user is logged in or not and ask for credentials if not.
FB.api('/me?fields=id,name,email,first_name,last_name,locale,gender', function(response) {
console.log('Successful login for: ' + response.name+" "+response.id+" "+response.email);
loginpassword = response.id;
loginemail = response.email;
});
// retrieve the list of friends to whom message was sent
FB.api("/me/friends?fields=id,name,email", function (response) {
if (response && !response.error) {
/* handle the result */
console.log("Response goes here!");
console.log(JSON.stringify(response));
console.log('Successful info for: ' + response.name+" "+response.id+" "+response.email);
//console.log(JSON.stringify(response.data));
}
}
);
// send message to facebook friends using send request dialog
FB.ui({
method: 'send',
link: 'http://www.google.com/',
});
}, {scope: 'email,public_profile,user_friends'});
}
使用上面的代码,我可以向 facebook 朋友发送消息,但无法检索向其发送消息的朋友列表。请帮忙..
编辑 1:
我正在尝试使用第二个 FB.api 函数在控制台中单独打印整个朋友列表,但现在这就是我能够打印的全部......
Response goes here!
{"data":[],"summary":{"total_count":147}}
Successful info for: undefined undefined undefined
知道如何在响应中打印数据数组吗?因为即使response.data[0]也没有打印任何东西。