如何调用FB.api

ram*_*z15 1 javascript facebook facebook-graph-api

我正在使用FB JavaScript SDK并完全遵循FB教程.我已经添加了登录按钮,使用我的FB帐户登录并尝试进行非常基本的FB.api呼叫,但即使在我使用Facebook登录后也没有得到正确的响应.这是代码:

 <script>
   window.fbAsyncInit = function() {
     FB.init({
       appId      : '291660820848913',
       status     : true, 
       cookie     : true,
       xfbml      : true,
       oauth      : true,
     });

   FB.api('/me', function(response) {
     alert(response.name);
   });  

   };
   (function(d){
      var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
      js = d.createElement('script'); js.id = id; js.async = true;
      js.src = "//connect.facebook.net/en_US/all.js";
      d.getElementsByTagName('head')[0].appendChild(js);
    }(document));

 </script>
Run Code Online (Sandbox Code Playgroud)

这给了我一个"未定义"的警报.难道我做错了什么?

DMC*_*MCS 5

   FB.api('/me', function(response) {
     alert(response.name);
   }); 
Run Code Online (Sandbox Code Playgroud)

只有在您知道用户已通过身份验证后才能执行此操作.你应该在打电话FB.getLoginStatus()之前拨打电话FB.api().