我正在使用 Facebook Connect php sdk 创建一个网站,当我使用 Facebook 登录时,它会正确登录 Facebook,但用户没有在我的网站上注册,所以用户没有登录。当我打印从脸书显示所有详细信息,如名字、姓氏、链接,但电子邮件和用户名字段保持空白。
This is my code,
> require 'facebook.php'; $facebook = new Facebook(array( 'appId' =>
> 'xxxxxxxxxx', 'secret' => 'xxxxxxxxxxxxxxxxxxxxxxx',
> ));
>
> $user = $facebook->getUser();
>
> $loginUrl = $facebook->getLoginUrl();
>
> if ($user) { try {
> $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) {
> error_log($e);
> $user = null; } } if ($user) {
> $facebook_userdetails = $facebook->api ( '/me' );
> // print_r($facebook_userdetails); exit; if (is_array($facebook_userdetails ))
> {
> $FBId = $facebook_userdetails ['id'];
> $FBName = $facebook_userdetails ['name'];
> $FBFirstName = $facebook_userdetails ['first_name'];
> $FBLastName = $facebook_userdetails ['last_name'];
> $FBLink = $facebook_userdetails ['link'];
> $FBUsername = $facebook_userdetails ['username'];
> $FBGender = $facebook_userdetails ['gender'];
> $FBEmail = $facebook_userdetails ['email'];
> $FBTimezone = $facebook_userdetails ['timezone'];
> $FBLocale = $facebook_userdetails ['locale'];
> $FBVerified = $facebook_userdetails ['verified'];
> $FBUpdated_time = $facebook_userdetails ['updated_time'];
> }
> else
> $this->view->error = $facebook_userdetails; echo "<body onLoad='myfunc()'>
> <form name='facebook' action='fbconnect_login.php' method='POST' id='face'>
> <input type='hidden' name='FBId' value='$FBId' />
> <input type='hidden' name='FBName' value='$FBName' />
> <input type='hidden' name='FBFirstName' value='$FBFirstName' />
> <input type='hidden' name='FBLastName' value='$FBLastName' />
> <input type='hidden' name='FBLink' value='$FBLink' />
> <input type='hidden' name='FBUsername' value='$FBUsername' />
> <input type='hidden' name='FBGender' value='$FBGender' />
> <input type='hidden' name='FBEmail' value='$FBEmail' />
> <input type='hidden' name='FBTimezone' value='$FBTimezone' />
> <input type='hidden' name='FBLocale' value='$FBLocale' />
> <input type='hidden' name='FBVerified' value='$FBVerified' />
> <input type='hidden' name='FBUpdated_time' value='$FBUpdated_time' />
> </form> </body>" ; $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl =
> $facebook->getLoginUrl(); echo "<script>window.location =
> '$loginUrl';</script>"; } $naitik = $facebook->api('/naitik'); ?>
> <script type="text/javascript"> function myfunc () { var frm =
> document.getElementById("face"); frm.submit(); } </script>
这是我的 html 内容,
<a id="fb-login" style="background:none;width:auto;height:25px;" class="fb_button fb_button_medium" href="javascript:void(0);">Login With Facebook</a>
<script type="text/javascript">
$('#fb-login').click(function()
var left = (screen.width/2)-(800/2);
var top = (screen.height/2)-(400/2);
signinWin = window.open("https://www.facebook.com/dialog/oauth?client_id=375057399186229&redirect_uri=http%3A%2F%2Flivedev.pharmacydirect.co.nz%2Fweb%2Ffb_main.php&state=69d3e5e4348786ab4bb4ab7f723c931a", "SignIn", "width=800,height=400,toolbar=0,scrollbars=1,status=0,resizable=0,location=0,menuBar=0,left="+left+",top="+top);
setTimeout(CheckLoginStatus, 2000);
signinWin.focus();
return false;
);
function CheckLoginStatus()
if (signinWin.closed)
window.location.reload();
else setTimeout(CheckLoginStatus, 1000);
</script>
任何帮助请,提前谢谢............