新的 Facebook 图形 api 已将朋友分为Friends
& Invitable_friends
。
me/friends/
返回我正在使用该应用程序的朋友,而me/invitable_friends/
仅返回我未使用该应用程序的朋友列表。
但是在我的应用程序中,用户也可能与可能不在他的朋友列表中的随机用户进行交互。
那么我如何获取那些正在使用该应用程序但不在我的朋友列表中的用户数据。
谢谢。
新的 Facebook 图形 api 已将朋友分为Friends
& Invitable_friends
。
me/friends/
返回我正在使用该应用程序的朋友,而me/invitable_friends/
仅返回我未使用该应用程序的朋友列表。
但是在我的应用程序中,用户也可能与可能不在他的朋友列表中的随机用户进行交互。
那么我如何获取那些正在使用该应用程序但不在我的朋友列表中的用户数据。
谢谢。
我遇到了同样的问题并这样解决了:默认情况下,当用户启动您的应用程序时,您会请求访问他的公共个人资料信息的权限,其中包括真实 ID、姓名和其他一些信息。您只需将用户数据(ID、姓名等)存储在数据库中。通过这种方式,您可以跟踪所有使用您的应用程序的人,并且他们可以相互交互。
JavaScript 示例:
window.fbAsyncInit = function () {
FB._https = true;
console.log('here');
FB.init({ appId: 'xxxxxxxxxxxxxxxx', cookie: true, xfbml: true, oauth: true, version : 'v2.0'});
Login();
};
function Login() {
FB.login(function(response) {
if (response.authResponse){
checkUser();
}
else{
console.log('User cancelled login or did not fully authorize.');
}
}
);
}
function checkUser() {
FB.api('/me', function(response) {
$.ajax({
type: "get",
url: "cgi-bin/checkUser.cgi",
cache: false,
data: {"user_name" : response.name, "u_id" : response.id, "link" : response.link},
success: function() //onSuccess,
{
console.log("user " + response.name + " checked!");
},
error: function()
{
console.log("Error with server connection on user checking");
}
});
});
}
我不知道您使用哪种语言编写应用程序,但我相信在每种语言中您都应该调用“登录”功能,该功能会向用户询问权限并基本上可以访问信息。
要获取正在使用该应用但不是您的朋友的用户的详细信息,请致电以下
graph.facebook.com/v2.0/
?ids={comma-separated-ids}&access_token=app_access_token&fields=name,picture
access_token 是必须的,否则 graph-api 返回以下错误-
The global ID xyz is not allowed. Please use the application specific ID instead.
这将适用于所有已对应用程序进行身份验证的用户,无论其身份验证日期如何,但对于任何非应用程序用户,graph-api 都会返回上述错误消息。