2012-04-19 6 views
1

私はFacebook Connectを使用して自分のウェブサイト用の新しいFacebook Appを開発しています。私はJS SDKを使用しており、ユーザーの名前を表示しようとしています。私のコードは次のとおりです。FB.apiの名前が定義されていません

window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : 'myappid', // App ID 
     oauth  : 'true', 
     channelUrl : '//mychannelfile', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 

    FB.Event.subscribe('auth.login', function (response) { 
       // do something with response 

      }); 

    var connecter=false; 

    FB.getLoginStatus(function(response) { 
      if (response.status === 'connected') { 
       connecter=true; 
       FB.api('/me', function(user) { 
       console.log(user.name); 
       }); 
      } 
     else connecter=false; 
     }); 
    }; 

コンソールをチェックすると、ユーザーが接続されたときにuser.nameの結果は未定義です。私は何が間違っているのか分かりません。

ありがとうございました!

+1

console.log(応答)オブジェクトとconsole.log(ユーザー)オブジェクトを確認しようとしましたか? – Dhiraj

+0

私はconsole.log(user.name)の前にconsole.log(user)を追加する理由を理解していません... – Kevin

+0

これはコンソールのユーザオブジェクトに名前属性があることを意味しますか? – Dhiraj

答えて

0
window.fbAsyncInit = function() { 
// init the FB JS SDK 
FB.init({ 
    appId  : '176854392480453',       
    status  : true,         
    xfbml  : true         
}); 

// Additional initialization code such as adding Event Listeners goes here 

FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
alert("connected"); 
connecter=true; 
FB.api('/me', function(user) { 
alert(user.name); 
alert(user.first_name); 
alert(user.last_name); 
alert(user.email); 
}); 

    } 
}); 
関連する問題