【发布时间】: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