Facebook示例JS登录未加载

Facebook example JS login not loading

本文关键字:加载 登录 JS 示例 Facebook      更新时间:2023-09-26

我正在尝试用JS替换我的画布应用程序的PHP登录名,并且几乎完全从这里 https://developers.facebook.com/docs/reference/javascript/和这里 https://developers.facebook.com/docs/reference/javascript/FB.login/复制了Facebook示例。 但是,即使警报提示正在打开,用户接受权限的提示也不会打开。 任何人都可以从下面的代码中看到原因吗? 我已经在这里呆了几个小时了,我看不出我的代码与建议的真正不同。 这可能与浏览器保护未运行javascript有关吗?

<?php
require_once 'config.php'; // This contains app information
//include_once 'scripts/mysql_connect.php'; // This is the database connection configuration
require_once 'Database.php';
$fbconfig['appUrl'] = "https://localhost/FindAFlatmate-Dev/";
?>
    <html>
    <!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>Profile Page</title>
    </head>
    <body> 
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : '127865210690483', // App ID
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });
        // Additional initialization code here
        alert('Api loaded');
    FB.login(function(response) {
       if (response.authResponse) {
         console.log('Welcome!  Fetching your information.... ');
         FB.api('/me', function(response) {
           console.log('Good to see you, ' + response.name + '.');
         });
       } else {
         console.log('User cancelled login or did not fully authorize.');
       }
     });
      };
      // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));
     </script>
    </body> 
    </html>

但是,即使警报提示正在打开,用户接受权限的提示也不会打开。任何人都可以从下面的代码中看到原因吗?

您直接在页面加载时调用FB.login,没有用户交互 - 因此很可能是浏览器的弹出窗口阻止程序阻止了登录对话框的显示。

FB.login的一般建议是仅在显式用户交互时调用它,例如用户单击显示"登录"或其他内容的链接/按钮。这样,弹出窗口FB.login打开的可能性较小,因为当前浏览器中弹出窗口阻止程序的默认配置是仅阻止"自动"打开的弹出窗口,而无需用户以任何方式请求它们。