【问题标题】:Facebook connect giving Redirecting LoopFacebook 连接提供重定向循环
【发布时间】:2013-11-05 01:59:02
【问题描述】:

我正在重定向循环,但我仍然无法弄清楚我在哪里做错了。

以下是我的应用设置:

config.php

session_start();
//Facebook App Id and Secret
$appID='xxx';
$appSecret='xxxxxxx';

$base_url = "http://localhost/xxx/fbsource/Source3/facebook/";

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login with Facebook</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/oauthpopup.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#facebook').click(function(e){
        $.oauthpopup({
            path: 'login.php',
            width:600,
            height:300,
            callback: function(){
                window.location.reload();
            }
        });
        e.preventDefault();
    });
});


</script>
</head>

<body>
<?php 
session_start();
if(!isset($_SESSION['User']) && empty($_SESSION['User']))   { ?>
<img src="images/facebook.png" id="facebook"  style="cursor:pointer;float:left;margin-left:550px;" />
<?php  }  else{

 echo '<img src="https://graph.facebook.com/'. $_SESSION['User']['id'] .'/picture" width="30" height="30"/><div>'.$_SESSION['User']['name'].'</div>';   
    echo '<a href="'.$_SESSION['logout'].'">Logout</a>';




}
    ?>

</body>
</html>

login.php

<?php 

require 'config.php';
require 'lib/facebook/facebook.php';

$facebook = new Facebook(array(
        'appId'     =>  $appID,
        'secret'    => $appSecret,
        ));
//get the user facebook id      
$user = $facebook->getUser();
$base_url = "http://localhost/xxx/fbsource/Source3/facebook/";
if($user){

    try{
        //get the facebook user profile data
        $user_profile = $facebook->api('/me');
        $params = array('next' => $base_url.'logout.php');
        //logout url
        $logout =$facebook->getLogoutUrl($params);
        $_SESSION['User']=$user_profile;
        $_SESSION['logout']=$logout;
    }catch(FacebookApiException $e){
        error_log($e);
        $user = NULL;
    }       
}

if(empty($user)){
//login url 
$loginurl = $facebook->getLoginUrl(array(
                'scope'         => 'email,read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
                'display'=>'popup'
                'redirect_url'=> $base_url."login.php";
                ));


header('Location: '.$loginurl);

}





?>
<!-- after authentication close the popup -->
<script type="text/javascript">

window.close();

</script>

我在 Chrome 和 IE10 上都测试过

【问题讨论】:

  • 有什么错误吗?哪个页面有循环?并且您需要从 config.php 中删除 session_start();,因为 facebook php SDK 文件提供了这一点
  • 没有错误。我在 login.php 上获得重定向
  • 将您的文件上传到公共服务器,它应该可以工作,因为 Facebook 无法访问 localhost
  • 这是我刚想出来的。当我在 Facebook 平台中制作 Facebook 应用程序时,这不是问题。我想知道为什么会出现这个问题?
  • 本地主机不工作,在公共 IP 上工作

标签: php facebook


【解决方案1】:

尽管过去可以在 WAMP、LAMP 和 MAMP (localhost) 上运行 Facebook 应用程序,但 Facebook 服务器无法访问localhost127.0.0.1

但它似乎不再起作用了,我在尝试测试/调试这些文件时遇到了同样的问题,但是 JS SDK 在任何地方都可以正常工作!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 2019-04-03
    • 2012-01-04
    • 1970-01-01
    相关资源
    最近更新 更多