在localhost上设置Facebook登录 [英] Setting up Facebook Login on localhost
问题描述
我一直在遵循这里列出的步骤来创建一个Facebook App登录:
http://developers.facebook.com/docs/howtos/login/server-side-login/
I've been following the steps outlined here to create a Facebook App Login: http://developers.facebook.com/docs/howtos/login/server-side-login/
我在第3步。我将本地设置在本地主机进行开发,然后我将使用不同的应用程序ID发布到Azure网站。我想让这个在localhost上工作。 (我还没有尝试使用非localhost域名。)
And am on Step 3. I'm setting this up on localhost for development and then I'll publish to Azure Websites with a different App ID. I'd like to have this working on localhost first though. (I haven't tried this with a non-localhost domain yet.)
在我的Facebook应用程序配置页面上,我设置了几个相关的字段:
网站URL:http:// localhost:8052 /(添加空格以允许submision to Stack Overflow)
应用程序域:localhost
On my Facebook App configuration page I've set a couple relevant fields: Site URL: http:// localhost : 8052/ (Spaces added to allow submision to Stack Overflow) App Domains: localhost
main.php重定向到登录页面如果没有设置Facebook代码。这工作正常。
main.php redirects to a login page if there is no Facebook code set. This works fine.
<head>
<?php
if(!isset($_SESSION['code'])) {
echo ('<meta http-equiv="REFRESH" content="0;url=/login.php" />');
}
?>
</head>
login.php使用从示例中复制的代码重定向到Facebook的登录页面。
login.php redirects to Facebook's login page using code copied from their example.
<?php
include '/lib/url.php';
$app_id = "XXXXX";
$app_secret = "XXXXX";
$my_url = CreateUrlForPage('welcome.php');
session_start();
$code = '';
if(!isset($_REQUEST["code"])) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
echo $my_url.'<br/>';
echo $dialog_url.'<br/>';
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
?>
显然我混淆了上面的应用程序ID。
Clearly I've obfuscated my App ID above.
我的CreateUrlForPage功能生成的网址与facebook登录网址一样很好:
The URL generated by my "CreateUrlForPage" function looks fine as does the facebook login URL:
http://localhost:8052/welcome.php
https://www.facebook.com/dialog/oauth?client_id=XXXX&redirect_uri=http%3A%2F%2Flocalhost%3A8052%2Fwelcome.php&state=XXXX
(再次,这里有一些混淆,真正的值看起来不错,第一个是整数,第二个是一个长十六进制字符串。)
(Again, some obfuscation here. The real values looked okay. The first being an integer the second being a long hex string.)
当导航到http:// localhost:8052 / login.php时,页面重定向到Facebook,并提供了一个完全无用的错误:一个错误发生了,请稍后再试。
When I navigate to http:// localhost : 8052/login.php, The page redirects to Facebook and gives a completely useless error: "An error occurred. Please try again later."
我在Stack Overflow上看了几个其他帖子,但他们没有解决我的问题。
I looked at a couple other posts on Stack Overflow, but they didn't solve my problem.
我正在看到的错误就像这里描述的错误:
本地主机上的Facebook应用程序登录错误
提供的建议是设置我已经完成的域和站点URL。
The error I'm getting looks just like the one described here: Facebook application login error on localhost The suggestion provided is to set the Domain and Site URL, which I've done.
还有一个链接到此问题:运行Facebook应用程序在本地主机上
他们再次建议网站URL。他们还谈论应用程序画布,这不是我正在使用的,我看不到它将如何与登录有关。
There is also a link to this question: Running Facebook application on localhost Again, they suggest Site URL. They also talk about app-canvas which is not something I'm using and I don't see how it would be related to login.
在设置站点URL和域之前,值得,我收到一个不同的错误 - 告诉我需要设置站点URL。 p>
For what it's worth, before I set the Site URL and Domain, I was getting a different error - one that told me I needed to set the Site URL.
推荐答案
这段代码为我工作。双重检查您的Facebook应用程序ID,我的网站url设置为http:// localhost:8052 / dont真的需要设置域名登录感谢
this code worked for me. double check your facebook app id and my site url is set to http:// localhost:8052/ dont really need to set domain name for login thanks
http://gamma.owlweb.com.ua/index.php/?route = account / register / fb
<?php
$app_id = "xxx"; $app_secret = "xxx";
$my_url ="http://localhost:3080/abc.php";
session_start();
$code = '';
if(!isset($_REQUEST["code"])) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
$dialog_url =
"https://www.facebook.com/dialog/oauth?client_id=".$app_id
."&redirect_uri=".urlencode($my_url)
."&state=".$_SESSION['state'];
echo $my_url.'<br/>';
echo $dialog_url.'<br/>';
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
?>
这篇关于在localhost上设置Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!