tags:

views:

29

answers:

1

I am doing a registration on my website via facebook.

When the user logs in via facebook the $user array returned is not exactly what i want.

I have gone through the user parameters that are accessible via facebook, i have tried implementing them also but it is not working.

This is a sample of what i have

require_once "Database_Connect.php";
if (!isset($_POST['choosepassword']))
{
 # We require the library
 $user=array();
 require("facebook.php");
 # my error tracker
 $error=0;

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

 # Let's see if we have an active session
 $session = $facebook->getSession();

 if(!empty($session)) {
  # Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
  try{
   $uid = $facebook->getUser();
   $user = $facebook->api('/me');
  } catch (Exception $e){}

  if(!empty($user)){
   # User info ok? Let's print it (Here we will be adding the login and registering routines)
   print_r($user);

   ***At this point what is retrieved is not exactly what i want*****

   $ue=$user['email'];$ui=$user['id'];
   $query = mysql_query("select * from members where email = '$ue' or (oauth_provider = 'facebook' AND oauth_uid = '$ui')", $link);
   $result = mysql_fetch_array($query);

   # If not, let's add it to the database
   if(!empty($result)){
    $error = 2; //record already in database
    require_once "facebook_error.php";
    die();
   }
  } else {
   # For testing purposes, if there was an error, let's kill the script
   $error = 1; //we were unable to retrieve info frm facebook
   require_once "facebook_error.php";
   die();
  }
 } else {
  # There's no active session, let's generate one
  $login_url = $facebook->getLoginUrl();

 *** I tried specifying what i want returned here, but it doesnt seem to work*****

  $url = $facebook->getLoginUrl(array(
  'req_perms' => 'uid, first_name, last_name, name, email, current_location, user_website, user_likes, user_interests, user_birthday, pic_big',
  'next' => 'http://www.zzzzzzz.com/facebook_register.php',
  'cancel_url' => 'http://www.zzzzzzz.com'

 ));
  header("Location: ".$login_url);
 }

What am i not doing right?

Thank You

Update

I am using FQL to select user info from facebook now,

$fql    =   "select uid, first_name, last_name, name, sex, email, current_location, website, interests, birthday, pic_big from user where uid=me()";
            $param  =   array('method' => 'fql.query', 'query' => $fql, 'callback' => '');
            $user   =   $facebook->api($param);

It retrieves all the data except the birthday and the email

How can i select the email and birthday?

Thanks

A: 

Your application needs the user_birthday and email permissions for this, else it will not return that information. You only need to supply parameters that need a permission, not what fields you want in the req_perms parameter, so it should look like this:

$url = $facebook->getLoginUrl(array(
  'req_perms' => 'email, user_birthday',
  'next' => 'http://www.zzzzzzz.com/facebook_register.php',
  'cancel_url' => 'http://www.zzzzzzz.com'
 ));
BeRecursive

related questions