您好我在登录whit facebook后试图从Facebook上获取用户的数据。但我的会话变量始终为null。我目前正在使用laravel 4框架。您正在看到的代码被称为来自facebook登录的回调函数。
$code = Input::get('code');
if (strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');
$facebook = new Facebook(Config::get('facebook'));
$uid = $facebook->getUser();
if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error');
$me = $facebook->api('/me');
$profile = Profile::whereUid($uid)->first();
if (empty($profile)) {
$user = new User;
$user->name = $me['first_name'].' '.$me['last_name'];
$user->email = $me['email'];
$user->save();
$profile = new Profile();
$profile->uid = $uid;
return $uid;
$profile->username = $me['name'];
$profile = $user->profiles()->save($profile);
}
$profile->access_token = $facebook->getAccessToken();
$profile->save();
$user = $profile->user;
Auth::login($user);
FacebookSession::setDefaultApplication(
Config::get('facebook.appId'),
Config::get('facebook.secret')
);
$helper = new FacebookRedirectLoginHelper('http://projectweb.app:8000/');
$session = $helper->getSessionFromRedirect();
if(isset($session))
{
$request = new FacebookRequest($session,'GET','/me');
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::classname());
$name = $graph->getName();
return $name;
}
else
{
return 'no sesssion';
}
答案 0 :(得分:0)
您最好尝试使用Laravel特定的包,在这里它是一个,您还可以在其中获得有关安装和使用它的详细信息。