Tester
Tester

Reputation: 2967

Facebook user email extended permissions with new SDK

I am currently using the code below in my Codeigniter application to get Facebook data from an app user.

<?php


 require_once('facebook-php-sdk/src/facebook.php');
// Create our Application instance (replace this with your appId and secret).
$facebook= new Facebook(array(
  'appId' => '2453463636',
      'secret' => '365653656565656',
      'allowSignedRequest' => false,
));

$_REQUEST += $_GET;
$user = $facebook->getUser();

if ($user) {
  try {
    // Get the user profile data you have permission to view
   // $user_profile = $facebook->api('/me');
    $user_profile = $facebook->api('/me?fields=picture.width(100).height(100),first_name,last_name,username,email');
    echo $user_profile['email'];
    echo $user_profile['username'];

  } catch (FacebookApiException $e) {
    $user = null;
  }
} else {
  die('<script>top.location.href="'.$facebook->getLoginUrl().'";</script>');
}

?>

This works fine in connecting and returns the username of the user echoed on the page, however the email does not work. The email returns shows up as an error on the view "Undefined index: email".

I used this very same thing to get the email just a few days ago and it worked, however that was on localhost. It get the email fine on localhost, when pushed to the server, it doesn't recognize email, but it does recognize and get the username.

Why isn't the email being recognized?

I am using the latest version of the sdk: Facebook PHP SDK (v.3.2.3)

Upvotes: 2

Views: 1056

Answers (1)

Kumar V
Kumar V

Reputation: 8830

You can't do with this options. You need extended permission from Facebook. Check this link for more details:

http://developers.facebook.com/docs/authentication/permissions/

Facebook Doesn't share user email without their permission.

Upvotes: 1

Related Questions