如果我设法获得response.session对象,我可以使用它来获取当前登录用户的用户名和个人资料图片吗?
由于
答案 0 :(得分:14)
FB.api('/me', function(response) {
alert("Name: "+ response.name + "\nFirst name: "+ response.first_name + "ID: "+response.id);
var img_link = "http://graph.facebook.com/"+response.id+"/picture"
});
更多信息:
http://developers.facebook.com/docs/reference/javascript/FB.api/
答案 1 :(得分:3)
此外,您可以获得有关已连接用户的更多个人信息:
FB.api('/me', function(response) {
console.log(response);
});
希望有所帮助
答案 2 :(得分:1)
以下是三种可能的状态:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and connected to your
// app, and response.authResponse supplies
// the user’s ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
//but not connected to the app
} else {
// the user isn't even logged in to Facebook.
}
});
答案 3 :(得分:0)
FB.getLoginStatus(function(response) {
if (response.session) {
//response.session contains what you lokks for
} else {
// user is not connected..
}
答案 4 :(得分:0)
如果用户已登录并已授权您的应用程序,则应该可以。
答案 5 :(得分:0)
之后,您设法获得响应会话对象,您可以执行以下操作
var rec="Name : "+response.name+"";
rec +="Link: "+response.link+"";
rec +="Username: "+response.username+"";
rec +="id: "+response.id+"";
rec +="Email: "+response.email+"";
function getPhoto()
{
FB.api('/me/picture?type=normal', function(response) {
var img=response.data.url;
});
有关详细信息,请参阅本手册: https://developers.facebook.com/docs/javascript/reference/FB.api