Buna ziua !
Am intampinat si eu o problema la un login cu facebook-ul . Cand incerc sa preiau sexul si emailul cu sdk-ul imi returneaza valorile NULL. Permisiuni am, datele pe profil m am asigurat ca sunt publice…care sa fie problema ?
<?php
//header('Access-Control-Allow-Origin: *');
// added in v4.0.0
require_once 'autoload.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;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication( '','' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://rezervari.simpapp.ro/naan/user.php' );
//$helper->getLoginUrl(array('scope' => 'email'));
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 ) && $_SESSION['service'] == 'facebook') {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['id'] = $fbid;
$_SESSION['name'] = $fbfullname;
$_SESSION['email'] = $femail;
$_SESSION['loggedIn'] = true;/* ---- header location after session ----*/
$_SESSION['user_pic'] = 'https://graph.facebook.com/'.$fbid.'/picture';
$_SESSION['gender'] = $graphObject->getProperty('sex');
if(!empty($s))
header("Location: http://rezervari.simpapp.ro/naan/user.php");
} else {
$loginUrl = $helper->getLoginUrl(array('scope' => 'email,public_profile'));
if($_SESSION['service'] == 'facebook' && !$_SESSION['loggedIn'])
echo '<script> window.location = "'.$loginUrl.'"; </script>';
}
?>