测试API Javascript不工作

Test API Javascript not working

本文关键字:工作 Javascript API 测试      更新时间:2023-09-26

我有这段代码,我是从facebook 的官方教程中得到的

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="fb-root">sei qui</div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '173721946132851',                        // App ID from the app dashboard
      channelUrl : '//www.ilmiobloggo.net/LOVECALCULATOR/index.php', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });
    // Additional initialization code such as adding Event Listeners goes here
  };
  // Load the SDK asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

   FB.api('/me', function(response) {
  alert('Your name is ' + response.name);
});
</script>

</body>
</html>

但是FB.api不起作用,我不明白为什么,有人可以帮我。我试图获得Apache日志错误到我的房子托管,但什么都没有。

尝试放置

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

在的下面

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

但高于

  };

例如

    window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
  appId      : '173721946132851',                        // App ID from the app dashboard
  channelUrl : '//www.ilmiobloggo.net/LOVECALCULATOR/index.php', // Channel file for x-domain comms
  status     : true,                                 // Check Facebook Login status
  xfbml      : true                                  // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
};

在创建FB之前,您正在调用FB.api。此外,这会产生JavaScript错误,这些错误会在浏览器中找到。Apache日志中没有。尝试打开Chrome开发工具/firebug等并查看控制台。

最后要注意的是,您没有任何代码供用户授权您的应用程序。除非用户已授予访问您帐户的权限,否则FB.api('/me')不会向您返回正确的响应,因为它需要用户访问令牌