我按照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,请将应用程序的所有域和子域添加到应用程序设置的“域”字段中。
答案 0 :(得分:0)
我设法在我的Laravel应用程序中连接fb和gmail auth。 问题是当我写127.0.0.1:8000/login/facebook不起作用,但使用localhost:8000 / login / facebook工作。 在开发人员fb页面中,设置基本选项卡下有网站URL输入框,在那里写http://localhost:8000/
答案 1 :(得分:-1)
也许它无法与localhost连接?
你可以尝试在主机上进行。