douteng5673 2013-09-16 07:19
浏览 34

此网页有一个重定向循环,但没有获取用户ID

I am using the following script of code and the page get stuck to infinite loop as it does not getting user id. Please help me.

<?php
include_once("facebook.php");

# Creating the facebook object  
$facebook = new Facebook(array(  
    'appId'  => 'xxxxxxxxxxxxxxxxxxxxxxxxx',  
    'secret' => 'xxxxxxxxxxxxxxxx',  
    'cookie' => true  
));  

$user = $facebook->getUser(); 
if($user) { 
    try{  
        $user = $facebook->api('/me');  
    } catch (Exception $e){}  
    if(!empty($user)){  
        print_r($user); 
    } 
    else { 
        die("There was an error.");  
    }  
} 
else {  
    $login_url = $facebook->getLoginUrl(array('scope'=>$fbPermissions,'redirect_uri'=>'http://www.mysit.com.com/script/check.php'));
    header("Location: ".$login_url);  
}
?>
  • 写回答

1条回答 默认 最新

  • doula2426 2013-09-16 08:48
    关注

    Because of this function its going in infinite redirect loop

    header("Location: ".$login_url);  
    

    Remove the above line from your code and add this line insted;

    echo 'Please <a href="' . $login_url . '">login.</a>';
    

    This link will take you to the page where you can login to the app.

    getLoginUrl() generates a new token. If your user is already logged in (with $user_id = $facebook->getUser()), you'll end up with 2 tokens.

    Don't ask for the $loginUrl if the user is authenticated already.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改