[英]Facebook javascript API: get username and image by session?
如果我設法獲得response.session對象,我可以使用它來獲取當前登錄用戶的用戶名和個人資料圖像嗎?
謝謝
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/
另外,您可以獲得有關連接用戶的更多個人信息:
FB.api('/me', function(response) {
console.log(response);
});
希望有所幫助
以下是三種可能的狀態:
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.
}
});
之后,您設法獲得響應會話對象,您可以執行以下操作
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
FB.getLoginStatus(function(response) {
if (response.session) {
//response.session contains what you lokks for
} else {
// user is not connected..
}
如果用戶已登錄並已授權您的應用程序,您應該能夠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.