Route::get('login/fb/callback', function() {
$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('/v2.4/me');
dd($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->photo = 'https://graph.facebook.com/'.$me['username'].'/picture?type=large';
$user->save();
$profile = new Profile();
$profile->uid = $uid;
$profile->username = $me['username'];
$profile = $user->profiles()->save($profile);
}
$profile->access_token = $facebook->getAccessToken();
$profile->save();
$user = $profile->user;
Auth::login($user);
return Redirect::to('/')->with('message', 'Logged in with Facebook');
});
我正在尝试获取first_name
,但它不存在。我得到的所有信息都是username
和id
。
我想我应该感到好奇#34; /我"别的什么,但我无法弄清楚到底是什么?
答案 0 :(得分:0)
在更改日志中搜索“声明字段”:https://developers.facebook.com/docs/apps/changelog#v2_4
您需要添加fields参数以获取其他数据:
$me = $facebook->api('/v2.4/me?fields=first_name');