我正在开发一个网站,用户可以在其中添加他们的 Facebook 好友。通常我会使用 apprequests,但此功能仅适用于 2.3 版及以上版本的游戏。目前我只能使用 send request Graph API 的功能可以向 friend 发送消息,但我还想检索向其发送消息的 friend 列表。
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 函数在控制台中单独打印整个 friend 列表,但现在这就是我能够打印的全部内容..
Response goes here!
{"data":[],"summary":{"total_count":147}}
Successful info for: undefined undefined undefined
知道如何打印响应中的数据数组吗?因为即使 response.data[0] 也没有打印任何内容。
最佳答案
正如您在文档中所读到的,使用发送对话框没有响应数据:https://developers.facebook.com/docs/sharing/reference/send-dialog
无法获取哪些好友收到消息的信息。
顺便说一句,如果您的应用程序不是使用 Canvas 的游戏,则发送对话框(或移动设备上的消息对话框)是邀请 friend 的唯一选项。
如果您想在用户的好友加入/授权该应用时向该用户发送通知,只需使用 user_friends
进行授权,然后向返回列表中的所有好友发送通知即可。毕竟,您只会获得那些已经授权您的应用程序的 friend 。您不需要为此存储受邀请的 friend 。
关于javascript - 将 Facebook 好友添加到网站 [Graph API 2.5],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35288453/