Facebook API使用户EMAIL无法在最新的SDK中使用

时间:2015-09-27 14:08:54

标签: facebook facebook-graph-api

似乎Facebook取消了检索用户电子邮件的能力,SDK版本中的任何一个都不能再这样做了,至少在我测试了很多版本之后,至少对我来说。

我在"注册Facebook"按钮,这就是我开始使用的:

<?php

session_start();

require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once('Facebook/Entities/AccessToken.php');
require_once('Facebook/HttpClients/FacebookHttpable.php');
require_once('Facebook/HttpClients/FacebookCurl.php');
require_once('Facebook/HttpClients/FacebookCurlHttpClient.php');
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;

// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('xxxxxxxx','xxxxxxxxx');

// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'http://xxxx/facebook/login-callback.php' );

try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}

// see if we have a session
if ( isset( $session ) ) {
  // graph api request for user data
  $request = new FacebookRequest( $session, 'GET', '/me?fields=email' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();

  // print data
  echo  print_r( $graphObject, 1 );
} else {
  // show login url
  echo '<a href="' . $helper->getLoginUrl(array('scope' => 'email')) .     '">Login</a>';
}

?>    

打印数据后:

Facebook\GraphObject Object ( [backingData:protected] => Array ( [id] => xxxxxxxxxx ) )    

未检索到电子邮件。

0 个答案:

没有答案