Facebook 登录按钮(在本地主机上): The Login Button plugin no longer works on http pages

标签 facebook facebook-graph-api facebook-javascript-sdk

好的,所以我有这个需要访问 FB api 才能发布内容的应用程序……事实上,我当然是在本地主机上试用我的应用程序。 (php5.6内部服务器)

我不断收到错误:

The Login Button plugin no longer works on http pages. Please update your site to use https for Facebook Login.

The method FB.getLoginStatus can no longer be called from http pages.

尽管人们一直在说本地主机不需要 https,但只要应用程序处于开发阶段,事实确实如此。

我想可能是因为我在端口 8000 上运行 php 服务器,但我使用 php5.6 -S localhost:80 检查以防万一,结果完全一样。

代码是:

<div id="fb-root"></div>
<div class="fb-login-button" data-width="" data-size="large" data-button-type="continue_with" data-auto-logout-link="false" data-use-continue-as="true"></div>


<script>
  function statusChangeCallback(response) {  // Called with the results from FB.getLoginStatus().
    console.log('statusChangeCallback');
    console.log(response);                   // The current login status of the person.
    if (response.status === 'connected') {   // Logged into your webpage and Facebook.
      testAPI();
    } else {                                 // Not logged into your webpage or we are unable to tell.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into this webpage.';
    }
  }


  function checkLoginState() {               // Called when a person is finished with the Login Button.
    FB.getLoginStatus(function(response) {   // See the onlogin handler
      statusChangeCallback(response);
    });
  }


  window.fbAsyncInit = function() {
    FB.init({
      appId      : '[totally valid id belonging to my development app I quadruple checked.]',
      cookie     : true,                     // Enable cookies to allow the server to access the session.
      xfbml      : true,                     // Parse social plugins on this webpage.
      version    : 'v5.0'           // Use this Graph API version for this call.
    });


    FB.getLoginStatus(function(response) {   // Called after the JS SDK has been initialized.
      statusChangeCallback(response);        // Returns the login status.
    });
  };


  (function(d, s, id) {                      // Load the SDK asynchronously
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));


  function testAPI() {                      // Testing Graph API after login.  See statusChangeCallback() for when this call is made.
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.name + '!';
    });
  }
</script>


<div id="status">
</div>

请帮帮我。我真的必须为此设置一个带有 https 等的服务器吗?

最佳答案

对于 node.js,您可以使用名为“devcert”的工具在本地主机上使用 https。

对于 PHP:

关于Facebook 登录按钮(在本地主机上): The Login Button plugin no longer works on http pages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59136008/

相关文章:

PHP curl 响应为 JSON 格式,但 var_dump 显示字符串

php - Facebook 的 5000 条 Post API 限制

javascript - Facebook {page-id}/tabs 不适用于 v2 sdk

javascript - 表单内联提交如何在Facebook请求页面上工作

Facebook API : any public way to get the count of followers for a specific page within a global page hierarchy?

Facebook JavaScript SDK 通过 HTTPS 加载非安全项目

javascript - 下划线将数组的键映射到另一个

php - 注册和登录最佳实践

ios - 解析和 Facebook 登录和注册返回 "User Cancelled Login"(iOS 8.1 + Swift 1.2)

facebook - 如何在测试 React.js 应用程序时从 Jest 获得测试覆盖率?