我无法通过我的facebook sdk v4过生日。以下是详细信息。
/* INCLUSION OF LIBRARY FILEs*/
require_once( 'lib/Facebook/FacebookSession.php');
require_once( 'lib/Facebook/FacebookRequest.php' );
require_once( 'lib/Facebook/FacebookResponse.php' );
require_once( 'lib/Facebook/FacebookSDKException.php' );
require_once( 'lib/Facebook/FacebookRequestException.php' );
require_once( 'lib/Facebook/FacebookRedirectLoginHelper.php');
require_once( 'lib/Facebook/FacebookAuthorizationException.php' );
require_once( 'lib/Facebook/GraphObject.php' );
require_once( 'lib/Facebook/GraphUser.php' );
require_once( 'lib/Facebook/GraphSessionInfo.php' );
require_once( 'lib/Facebook/Entities/AccessToken.php');
require_once( 'lib/Facebook/HttpClients/FacebookCurl.php' );
require_once( 'lib/Facebook/HttpClients/FacebookHttpable.php');
require_once( 'lib/Facebook/HttpClients/FacebookCurlHttpClient.php');
/* USE NAMESPACES */
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\GraphUser;
use Facebook\GraphSessionInfo;
use Facebook\FacebookHttpable;
use Facebook\FacebookCurlHttpClient;
use Facebook\FacebookCurl;
/*PROCESS*/
//1.Stat Session
session_start();
//check if users wants to logout
if($_REQUEST['logout']==1){
unset($_SESSION['fb_token']);
}
//2.Use app id,secret and redirect url
$app_id = 'xxxxxxxxxxx';
$app_secret = 'xxxxxxxxxxxxxxxx';
$redirect_url='http://someurl.co//';
//3.Initialize application, create helper object and get fb sess
FacebookSession::setDefaultApplication($app_id,$app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
$sess = $helper->getSessionFromRedirect();
//check if facebook session exists
if(isset($_SESSION['fb_token'])){
$sess = new FacebookSession($_SESSION['fb_token']);
}
//logout
$logout = 'http://dryvr.co/fb/?logout=1';
//4. if fb sess exists echo name
if(isset($sess)){
//store the token in the php session
$_SESSION['fb_token']=$sess->getToken();
//create request object,execute and capture response
$request = new FacebookRequest($sess,'GET','/me?fields=id,name,email,birthday');
// from response get graph object
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::classname());
// use graph object methods to get user details
$name = $graph->getName();
$id = $graph->getId();
$birthday = $graph->getBirthday();
$image = 'https://graph.facebook.com/'.$id.'/picture?width=300';
$email = $graph->getProperty('email');
$birthday = $graph->getProperty('birthday');
echo "hi $name <br>";
echo "your email is $email <br>";
echo "your birthday is on $birthday <br>";
echo "<a href='".$logout."'><button>Logout</button></a>";
}else{
//else echo login
echo '<a href="'.$helper->getLoginUrl(array('email')).'" >Login with facebook</a>';
}
同样在graphUser.php中,我有这个功能
public function getBirthday()
{
$value = $this->getProperty('birthday');
if ($value) {
return new \DateTime($value);
}
return null;
}
我已经尝试了$graph->getBirthday()
和$graph->getProperty('birthday')
,但我似乎无法回应它。我怎么过生日礼物?我正在使用$birthday
变量。我在回应它,但它是空白的。
提前致谢
答案 0 :(得分:0)
这与您昨天发布的问题基本相同,现在使用birthday
代替email
。如果您未在user_birthday
的登录范围中指定相应的权限(getLoginUrl()
),则您将永远无法获取数据。
请阅读相应的文档,它就在那里!
见