FB.api 名称未定义

FB.api name undefined

本文关键字:未定义 api FB      更新时间:2023-09-26

我正在使用Facebook Connect为我的网站开发一个新的Facebook应用程序。我正在使用 JS SDK,并尝试显示用户的名称。这是我的代码:

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 的结果。我不明白我做错了什么。

感谢您的帮助!

  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);
});
  } 
 });