Facebook PHP SDK无法检索用户电子邮件

时间:2017-02-18 13:00:31

标签: php facebook sdk deprecated

这是我的代码:

    <?php

session_start();

require '../src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => '...',
  'secret' => '...',
));

// See if there is a user from a cookie
$user = $facebook->getUser(array("email"));

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me',array('fields' => 'id,name,email,first_name,last_name'));
  } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user) { ?>
      Your user profile is
      <pre>
        <?php print htmlspecialchars(print_r($user_profile, true)) ?>
      </pre>
    <?php } else { ?>
      <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
  </body>
</html>
enter code here

缺少电子邮件。如何申请用户的电子邮件地址? 我可以想象我必须在我的Facebook应用程序中设置一个复选框? 我有PHP 5.3.3,并且不能使用Facebook图形SDK。 输出仅包含&#34; name&#34;,&#34; fitst_name&#34;,&#34; last_name&#34;和&#34; id&#34;。

0 个答案:

没有答案