/** * undocumented function * * @return void * @author **/ public function takeCare() { $req = Request::instance(); $config = Config::get('rjvim.connect.facebook.clients.' . $this->client); $helper = new LaravelFacebookRedirectLoginHelper($config['redirect_uri']); try { $session = $helper->getSessionFromRedirect(); } catch (FacebookRequestException $ex) { dd($ex); } catch (\Exception $ex) { dd($ex); } if ($session) { try { $user_profile = (new FacebookRequest($session, 'GET', '/me?fields=id,name,email,birthday,location,gender,bio,link'))->execute()->getGraphObject(GraphUser::className()); // dd($user_profile); $user_image = (new FacebookRequest($session, 'GET', '/me/picture', array('redirect' => false, 'height' => '200', 'type' => 'normal', 'width' => '200')))->execute()->getGraphObject()->asArray(); } catch (FacebookRequestException $e) { dd('There was some error!'); } catch (FacebookSDKException $e) { dd('There was some error!'); } $user_profile = $user_profile->asArray(); $result = []; $result['uid'] = isset($user_profile['id']) ? $user_profile['id'] : ''; $result['name'] = isset($user_profile['name']) ? $user_profile['name'] : ''; $result['gender'] = isset($user_profile['gender']) ? $user_profile['gender'] : ''; $result['birthday'] = isset($user_profile['birthday']) ? $user_profile['birthday'] : ''; $result['link'] = isset($user_profile['link']) ? $user_profile['link'] : ''; if ($this->sentry->check()) { $result['email'] = $this->sentry->getUser()->email; } else { $result['email'] = $user_profile['email']; } $result['username'] = $result['name']; $result['location'] = isset($user_profile['location']->name) ? $user_profile['location']->name : ''; $fresult = $this->findUser($result['email']); if ($fresult['found']) { $fuser = $fresult['user']; $result['name'] = $fuser->name; } else { $result['name'] = $result['name']; } $result['access_token'] = $session->getLongLivedSession()->getToken(); if (!$user_image['is_silhouette']) { $result['image_url'] = $user_image['url']; } $result['image'] = $user_image['url']; return $result; } }
/** * undocumented function * * @return void * @author **/ public function takeCare() { $req = Request::instance(); $config = Config::get('connect::facebook.clients.' . $this->client); $helper = new LaravelFacebookRedirectLoginHelper($config['redirect_uri']); try { $session = $helper->getSessionFromRedirect(); } catch (FacebookRequestException $ex) { dd($ex); } catch (\Exception $ex) { dd($ex); } if ($session) { try { $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className()); $user_image = (new FacebookRequest($session, 'GET', '/me/picture', array('redirect' => false, 'height' => '200', 'type' => 'normal', 'width' => '200')))->execute()->getGraphObject()->asArray(); } catch (FacebookRequestException $e) { dd('There was some error!'); } catch (FacebookSDKException $e) { dd('There was some error!'); } $result['uid'] = $user_profile->getId(); if ($this->sentry->check()) { $result['email'] = $this->sentry->getUser()->email; } else { $result['email'] = $user_profile->getEmail(); } $result['url'] = $user_profile->getLink(); $result['location'] = $user_profile->getLocation(); $fresult = $this->findUser($result['email']); if ($fresult['found']) { $fuser = $fresult['user']; $result['first_name'] = $fuser->first_name; $result['last_name'] = $fuser->last_name; } else { $result['first_name'] = $user_profile->getFirstName(); $result['last_name'] = $user_profile->getLastName(); } $result['username'] = $user_profile->getFirstName() . ' ' . $user_profile->getLastName(); $result['name'] = $result['username']; $result['access_token'] = $session->getLongLivedSession()->getToken(); if (!$user_image['is_silhouette']) { $result['image_url'] = $user_image['url']; } return $result; } }