javascript - FB.api 名称未定义

标签 javascript facebook sdk

我正在使用 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);
});

  } 
 });

关于javascript - FB.api 名称未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10236213/

相关文章:

javascript - FCM 推送通知消息不显示

ios - 了解iOS应用程序打包了哪些库

iOS 模拟器不运行

javascript - 如何更改点击事件上的字形图标类?

javascript 函数在node.js Jade Express 中不起作用

javascript - 如何递归获取父子名称

javascript - Facebook "Like"按钮回调

php - 如何在不使用 api 资源管理器的情况下获取具有以前使用的权限的新 'short lived' facebook 访问 token (服务器端)?

javascript - 是否可以使用 jQuery 检索 Facebook 状态?

android - 无法运行我的信标应用程序,因为 kontakt sdk 错误