【问题标题】:Unable to connect my laravel app with facebook authentification无法将我的 laravel 应用程序与 facebook 身份验证连接起来
【发布时间】:2018-04-26 09:19:06
【问题描述】:

我按照 Sriram Ranganathan 在此线程 How to integrate Facebook PHP SDK with Laravel 5.4? 中给出的说明进行操作。

这是我登录页面的代码:

<fb:login-button  id="btn-login" class="btn w-md btn-bordered btn-primary 
waves-effect waves-light" type="button">Via <i class="fa fa-facebook- 
official"></i>
</fb:login-button>

<script>
    $(document).ready(function() 
    {
    $.ajaxSetup({ cache: true }); // since I am using jquery as well in my app
    $.getScript('//connect.facebook.net/en_US/sdk.js', function () {
        // initialize facebook sdk
        FB.init({
            appId: '866665793537033', // replace this with your id
            status: true,
            cookie: true,
            version: 'v2.8'
        });

        // attach login click event handler
        $("#btn-login").click(function(){
            FB.login(processLoginClick, {scope:'public_profile,email,user_friends,manage_pages', return_scopes: true});  
        });
    });
    });

    // function to send uid and access_token back to server
    // actual permissions granted by user are also included just as an addition
    function processLoginClick (response) 
    {    
        var uid = response.authResponse.userID;
        var access_token = response.authResponse.accessToken;
        var permissions = response.authResponse.grantedScopes;
        var data = { uid:uid, 
                     access_token:access_token, 
                     _token:'{{ csrf_token() }}', // this is important for Laravel to receive the data
                     permissions:permissions 
                   };        
        postData("{{ url('/login') }}", data, "post");
    }

    // function to post any data to server
    function postData(url, data, method) 
    {
        method = method || "post";
        var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", url);
        for(var key in data) {
            if(data.hasOwnProperty(key)) 
            {
                var hiddenField = document.createElement("input");
                hiddenField.setAttribute("type", "hidden");
                hiddenField.setAttribute("name", key);
                hiddenField.setAttribute("value", data[key]);
                form.appendChild(hiddenField);
             }
        }
        document.body.appendChild(form);
        form.submit();
    }
</script>

these are the settings of my app on facebook

当我尝试连接时出现此错误:

无法加载此 URL:此 URL 的域未在应用程序的域中注册。要导入此 URL,请将应用程序的所有域和子域添加到应用程序设置的域字段。

【问题讨论】:

  • 我的法语不好,但我相信错误消息是在重定向身份验证链接中要求https 链接。
  • 消息说:“为了增强安全性,你应该激活 HTTPS”
  • 是的。这就是我要说的。
  • 所以我应该让我的项目可以通过 https 访问,然后在 facebook 设置中激活它
  • 这只是相关设置的一部分,您还需要指定有效的 OAuth 重定向 URI,developers.facebook.com/docs/facebook-login/…

标签: laravel facebook-graph-api


【解决方案1】:

我设法在我的 Laravel 应用程序中连接了 fb 和 gmail auth。 问题是当我写 127.0.0.1:8000/login/facebook 时不起作用,但使用 localhost:8000/login/facebook 可以。 并且在开发者fb页面中设置基本选项卡下有网站url输入框写有http://localhost:8000/

【讨论】:

  • 同样的问题我只使用 localhost 在我的例子中 localhost:80
  • 这里你会看到客户端 OAuth 登录,Web OAuth 登录让他们是的
【解决方案2】:

可能无法连接本地主机?

你可以试试在主机上做。

【讨论】:

  • 问题是我现在必须让它在本地运行,然后在主机上运行
  • 我的法语不太好,但截图说明了 HTTPS,我认为这是唯一的方法
  • 消息说:“为了增强安全性,你应该激活 HTTPS”
  • 我明白了,你能解释一下你到底在哪里得到了错误“无法加载这个 URL”。这是在 laravel 还是在 facebook 上
  • 在我的 laravel 应用程序的登录页面中,我有一个带有 laravel 身份验证的普通登录按钮和第二个按钮,用于尝试使用 facebook 数据连接到我的应用程序。当我单击它进行连接时,我得到了那个错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
  • 1970-01-01
相关资源
最近更新 更多