无法为Facebook创建登录会话

时间:2013-01-19 22:51:50

标签: php facebook

我一直在使用以下代码 1)检查是否有facebook会话打开,如果打开获取名称(第一个和最后一个)和电子邮件。该页面是facebook_signup.php 2)如果没有,请使用facebook注册并将会话保存到signup.php中的数据库中。

以下是facebook_signup.php的代码。

<?php

// Awesome FB APP 
// Name: MyAPP 

require_once 'facebook-php-sdk-master/src/facebook.php';// this line calls our       facebook.php file that is the 
//core of PHP facebook API
// Create our Application instance.

$facebook = new Facebook(array(

'appId' => 'xxxxx',

'secret' => 'xxxxx',

'cookie' => true,

 )); // all we are doing is creating an array for facebook to use with our 

 $user = $facebook->getUser();
 echo $user;
 //app id and app secret in and setting the cookie to true
 if($user){
 try {
 $user_profile = $facebook->api('/me');
 } catch (FacebookApiException $e) {
 error_log($e);
 $user=null;

 } // this code is saying if the session to the app is created use 
 }
 //the $me as a selector for the information or die

 ?>

 <!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>Facebook APP</title>
 </head>

 <body>

 <? if ($user) { ?>
 <form action='signup.php' method='post'>

 <fieldset class="field_name">
 <label>First Name</label>
 <input class="name" name="first_name" type="text" value=" <? if ($user) 
 {echo $me['first_name'];} else{echo 'First Name';} ?>" >
 </fieldset>

 <fieldset class='field_name'>
 <label>Last Name</label>
 <input class="name" name="last_name" type="text" value="<? if ($user)
 {echo $me['last_name'];}else{echo'Last Name';} ?>" >
 </fieldset>

 <fieldset>
 <label>Email Address</label>
 <input name="email" type="text" value="<? if ($user) 
 {echo $me['email'];}else{echo'email address';} ?>" >
 </fieldset>

 <fieldset>
 <input name="submit" type="submit" value="submit" />
 </fieldset>

 </form>

 <? } else { ?>

 <p>Sign up with Facebook <fb:login-button perms='email'> Connect</fb:login-button>

 It only takes a few seconds</p>

 <div id='fb-root'></div>

  <script src='http://connect.facebook.net/en_US/all.js'></script>

  <script>

     FB.init({ 

        appId:'250941738370233', cookie:true, 

        status:true, xfbml:true 

     });

     FB.Event.subscribe('auth.login', function(response) {

    window.location.reload(); //will reload your page you are on

  });

  </script> 

  <? } ?> 
  </body>
  </html>

有人可以告诉我为什么我登录Facebook时仍然无法获得用户登录会话。同样在值字段中,意外的结果即将到来(出错了)。对这件事情不熟悉并试图将用户会话(姓名和电子邮件)保存到数据库中。

0 个答案:

没有答案