当前位置: 首页>>代码示例>>PHP>>正文


PHP Facebook\GraphUser类代码示例

本文整理汇总了PHP中Facebook\GraphUser的典型用法代码示例。如果您正苦于以下问题:PHP GraphUser类的具体用法?PHP GraphUser怎么用?PHP GraphUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GraphUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createUserProfile

 private function createUserProfile(FacebookSession $session, GraphUser $user)
 {
     $profile = new UserProfile();
     $profilePicReq = new FacebookRequest($session, 'GET', '/me/picture', ['redirect' => 0, 'type' => 'large']);
     $pic = $profilePicReq->execute()->getGraphObject()->asArray();
     $profile['displayName'] = $user->getName();
     $profile['profileUrl'] = $user->getLink();
     $profile['imageUrl'] = $pic['url'];
     //TODO other props
     return $profile;
 }
开发者ID:kapitchi,项目名称:kap-security,代码行数:11,代码来源:FacebookJavascript.php

示例2: loginFacebookAction

 public function loginFacebookAction()
 {
     $response = array("status" => 0, "message" => "Thao tác không thành công");
     if (!empty($this->user)) {
         $response["status"] = 1;
     } else {
         if ($this->request->isPost()) {
             $acesstoken = $this->request->getPost("accesstoken", null, false);
             \Facebook\FacebookSession::setDefaultApplication($this->config["FACEBOOK_ID"], $this->config["FACEBOOK_SECRET"]);
             $session = new \Facebook\FacebookSession($acesstoken);
             if ($session) {
                 $user_profile = (new \Facebook\FacebookRequest($session, 'GET', '/me', ['fields' => 'id,name,email']))->execute()->getGraphObject(\Facebook\GraphUser::className());
                 if (!empty($user_profile)) {
                     $email = $user_profile->getEmail();
                     $id = $user_profile->getId();
                     $username = explode("@", $email);
                     $username = $username[0] . "_fb_" . $id;
                     $data_user = array("email" => $email, "nickname" => $user_profile->getName(), "username" => $username, "id" => $id);
                     $response = $this->doSocialLogin($data_user);
                 }
             }
         }
     }
     echo json_encode($response);
     exit;
 }
开发者ID:nbtai,项目名称:haiquan,代码行数:26,代码来源:UserController.php

示例3: facebook

 public function facebook()
 {
     if (Session::has('flash_notification.message')) {
         return view('auth.facebook');
     }
     $config = config('services.facebook');
     session_start();
     FacebookSession::setDefaultApplication($config['id'], $config['secret']);
     $helper = new FacebookRedirectLoginHelper(route('facebook'));
     if (!Input::has('code')) {
         return redirect($helper->getLoginUrl(['email']));
     }
     try {
         $session = $helper->getSessionFromRedirect();
         $profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
     } catch (FacebookRequestException $e) {
         flash('Ne pare rău dar a apărut o eroare. <a href="' . route('facebook') . '">Încearcă din nou</a>.', 'danger');
         return redirect()->route('facebook');
     }
     if ($user = $this->userRepo->getByFacebook($profile->getId())) {
         return $this->loginUser($user);
     }
     if (empty($profile->getProperty('email'))) {
         flash('<p>Nu am putut citi adresa de email asociată contului tău de Facebook.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o adresă de email validă</p>', 'danger');
         return redirect()->route('facebook');
     }
     if ($this->userRepo->getByEmail($profile->getProperty('email'))) {
         flash('<p>Adresa de email asociată contului tău de Facebook este deja folosită pe site de altcineva.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o altă adresă de email.</p>', 'danger');
         return redirect()->route('facebook');
     }
     $user = User::create(['email' => $profile->getProperty('email'), 'first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'avatar' => $this->getFacebookPictureUrl($session), 'role_id' => config('auth.default_role_id'), 'confirmed' => 1, 'county_id' => 20]);
     $user->setMeta('facebook', $profile->getId());
     $user->save();
     return $this->loginUser($user);
 }
开发者ID:adriancatalinsv,项目名称:fiip,代码行数:35,代码来源:OAuthController.php

示例4: MeAction

 public function MeAction($params)
 {
     $ACCESS_TOKEN = isset($params[self::AUTH_TOKEN]) ? $params[self::AUTH_TOKEN] : null;
     $USER_ID = isset($params[self::USER_ID]) ? $params[self::USER_ID] : null;
     // 1. If IS NOT set access token - get from DB by USER_ID
     if (empty($ACCESS_TOKEN)) {
         if (empty($USER_ID)) {
             throw new FacebookSDKException('To get access token you need to supply USER_ID');
         }
         $params_social = array(\Av\MediaUserModel::MEDIA_ID => \Av\MediaModel::MEDIA_FACEBOOK, \Av\MediaUserModel::USER_ID => $USER_ID);
         $oSocialUserMapper = new \Av\MediaUserModel();
         $access_token_info = $oSocialUserMapper->GetCredentials($params_social);
         $ACCESS_TOKEN = isset($access_token_info[\Av\MediaUserModel::ACCESS_TOKEN]) ? $access_token_info[\Av\MediaUserModel::ACCESS_TOKEN] : null;
         if (empty($ACCESS_TOKEN)) {
             throw new FacebookSDKException("No  access token is saved for USER_ID {$USER_ID}");
         }
     }
     $session = new FacebookSession($ACCESS_TOKEN);
     try {
         $fbRequest = new FacebookRequest($session, 'GET', '/me');
         $user_profile = $fbRequest->execute()->getGraphObject(GraphUser::className());
         $this->SetMediaUserId($user_profile->getId());
         $this->SetUserEmail($user_profile->getEmail());
         $this->SetName($user_profile->getName());
         $this->SetVerified($user_profile->getVerified());
     } catch (FacebookRequestException $e) {
         echo __METHOD__ . __LINE__ . " Facebook  error during authentication <br><pre>";
         var_dump($e);
         echo "</pre>";
         return;
     }
 }
开发者ID:avassilenko,项目名称:av_2,代码行数:32,代码来源:FacebookServicePersonController.php

示例5: getCurrentSession

 public function getCurrentSession()
 {
     $helper = new FacebookJavaScriptLoginHelper();
     try {
         if (!empty($_SESSION[self::SessionKey])) {
             $accessToken = $_SESSION[self::SessionKey];
             $_SESSION[self::SessionKey] = null;
             $session = new \Facebook\FacebookSession($accessToken);
         } else {
             $session = $helper->getSession();
             $accessToken = $session->getAccessToken();
             $_SESSION[self::SessionKey] = (string) $accessToken;
         }
     } catch (\Exception $ex) {
         Record::add(__CLASS__, $ex->getMessage(), $ex);
         throw $ex;
     }
     if ($session) {
         try {
             $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
             return ['id' => $user_profile->getId(), 'name' => $user_profile->getName()];
         } catch (FacebookRequestException $e) {
             $error = "Exception occured, code: " . $e->getCode() . " with message: " . $e->getMessage();
             Record::add(__CLASS__, $error, $e);
             throw $e;
         }
     }
 }
开发者ID:gudwin,项目名称:extasy,代码行数:28,代码来源:FacebookApi.php

示例6: apiAction

 /**
  * @Route("/fb")
  */
 public function apiAction()
 {
     // ustawiamy ID aplikacji i client secret
     FacebookSession::setDefaultApplication(FB_APP_ID, FB_APP_SECRET);
     // tworzymy helpera do zalogowania się
     $helper = new FacebookRedirectLoginHelper(FB_APP_REDIRECT_URI);
     // Pobieramy token sesji
     try {
         $session = $helper->getSessionFromRedirect();
         // Logowanie...
     } catch (FacebookRequestException $ex) {
         // jeśli błąd Facebooka
     } catch (\Exception $ex) {
         // jeśli ogólnie błąd
     }
     if ($session) {
         // Zalogowany
         echo 'Logged';
         // pobieramy profil zalogowanego użytkownika
         $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
         // obiekt z danymi zalogowanego użytkownika:
         var_dump($user_profile);
     } else {
         // Link do logowania
         echo '<a href="' . $helper->getLoginUrl(array('email', 'user_friends')) . '">Login</a>';
     }
     return $this->render('Api/api.html.twig');
 }
开发者ID:KrzysztofSpetkowski,项目名称:GraphApi,代码行数:31,代码来源:ApiController.php

示例7: user

 public static function user()
 {
     if (self::$user !== false) {
         return self::$user;
     }
     FacebookSession::setDefaultApplication(\Config::get('fb-auth::config.facebook_app_id'), \Config::get('fb-auth::config.facebook_secret'));
     $token = \Input::get('accessToken');
     if (!$token) {
         $token = \Request::header('FB-Access-Token');
     }
     if (!$token) {
         self::$user = null;
         return null;
     }
     $session = new FacebookSession($token);
     try {
         $me = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
         self::$user = \User::from_fb($me);
     } catch (FacebookAuthorizationException $e) {
         self::$user = null;
     } catch (FacebookRequestException $e) {
         self::$user = null;
     } catch (\Exception $e) {
         self::$user = null;
     }
     return self::$user;
 }
开发者ID:benallfree,项目名称:laravel-fb-auth,代码行数:27,代码来源:Auth.php

示例8: connect

 public function connect()
 {
     // check we have a valid session
     $appId = Config::inst()->get('FacebookControllerExtension', 'app_id');
     $secret = Config::inst()->get('FacebookControllerExtension', 'api_secret');
     $session = $this->getFacebookHelper()->getSessionFromRedirect();
     if ($session) {
         $token = $session->getAccessToken();
         // get a long lived token by default. Access token is saved in
         // session.
         try {
             $long = $token->extend($appId, $secret);
             if ($long) {
                 $accessTokenValue = (string) $long;
             } else {
                 $accessTokenValue = (string) $token;
             }
         } catch (Exception $e) {
             $accessTokenValue = (string) $token;
         }
         try {
             Session::set(FacebookControllerExtension::FACEBOOK_ACCESS_TOKEN, $accessTokenValue);
             $fields = Config::inst()->get('FacebookControllerExtension', 'facebook_fields');
             $user = (new FacebookRequest($session, 'GET', '/me', array('fields' => implode(',', $fields))))->execute()->getGraphObject(GraphUser::className());
             if (!($member = Member::currentUser())) {
                 // member is not currently logged into SilverStripe. Look up
                 // for a member with the UID which matches first.
                 $member = Member::get()->filter(array("FacebookUID" => $user->getId()))->first();
                 if (!$member) {
                     // see if we have a match based on email. From a
                     // security point of view, users have to confirm their
                     // email address in facebook so doing a match up is fine
                     $email = $user->getProperty('email');
                     if ($email) {
                         $member = Member::get()->filter(array('Email' => $email))->first();
                     }
                 }
                 if (!$member) {
                     $member = Injector::inst()->create('Member');
                 }
             }
             $member->syncFacebookDetails($user);
             $member->logIn();
             // redirect the user to the provided url, otherwise take them
             // back to the route of the website.
             if ($url = Session::get(FacebookControllerExtension::SESSION_REDIRECT_URL_FLAG)) {
                 return $this->redirect($url);
             } else {
                 return $this->redirect(Director::absoluteBaseUrl());
             }
         } catch (Exception $e) {
             SS_Log::log($e, SS_Log::ERR);
         }
     } else {
         return $this->httpError(400);
     }
     return $this->httpError(400);
 }
开发者ID:wilr,项目名称:silverstripe-facebookconnect,代码行数:58,代码来源:FacebookConnectAuthCallback.php

示例9: getUserProfile

 public function getUserProfile()
 {
     try {
         $user_profile = (new FacebookRequest($this->session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
         return $user_profile;
     } catch (FacebookRequestException $e) {
         return false;
     }
 }
开发者ID:wunderfactory,项目名称:weinform,代码行数:9,代码来源:Facebook.php

示例10: validateRequest

 public function validateRequest(RequestInterface $request, ResponseInterface $response)
 {
     $identifier = $this->getQuerystringIdentifier();
     if (!$request->request($identifier)) {
         $response->setError(400, 'invalid_request', 'Missing parameters: "' . $identifier . '" required');
         return null;
     }
     $fb_app_id = Config::get('api-foundation::fb_app_id');
     $fb_app_secret = Config::get('api-foundation::fb_app_secret');
     if (empty($fb_app_id)) {
         throw new \LogicException('Facebook APP ID not set.');
     }
     if (empty($fb_app_secret)) {
         throw new \LogicException('Facebook APP SECRET not set.');
     }
     FacebookSession::setDefaultApplication($fb_app_id, $fb_app_secret);
     try {
         $session = new FacebookSession($request->request($identifier));
     } catch (FacebookRequestException $e) {
         $response->setError(401, 'invalid_grant', $e->getMessage());
         return null;
     } catch (\Exception $e) {
         $response->setError(401, 'invalid_grant', $e->getMessage());
         return null;
     }
     if (!empty($session)) {
         try {
             $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
             $email = $user_profile->getProperty('email');
             if (empty($email)) {
                 $response->setError(400, 'invalid_request', "User's email address not available.");
                 return null;
             } else {
                 $userInfo = $this->storage->getUserInfoByFacebookId($user_profile->getId());
                 if (empty($userInfo)) {
                     $this->storage->createFacebookUser($user_profile);
                     $userInfo = $this->storage->getUserInfoByFacebookId($user_profile->getId());
                 }
             }
         } catch (FacebookRequestException $e) {
             $response->setError(401, 'invalid_grant', $e->getMessage());
             return null;
         }
     } else {
         $response->setError(401, 'invalid_grant', 'Facebook session could not be set with supplied access token.');
         return null;
     }
     if (empty($userInfo)) {
         $response->setError(400, 'invalid_grant', 'Unable to retrieve user information.');
         return null;
     }
     if (!isset($userInfo['user_id'])) {
         throw new \LogicException("You must set the user_id on the array.");
     }
     $this->userInfo = $userInfo;
     return true;
 }
开发者ID:shaunpersad,项目名称:api-foundation,代码行数:57,代码来源:FacebookAccessToken.php

示例11: getUser

 public function getUser($userId = 'me')
 {
     try {
         $request = new FacebookRequest($this->getSession(), 'GET', '/' . $userId);
         return $request->execute()->getGraphObject(GraphUser::className())->asArray();
     } catch (Exception $e) {
     }
     return [];
 }
开发者ID:garyrutland,项目名称:yii2-facebook-sdk,代码行数:9,代码来源:Facebook.php

示例12: testMeReturnsGraphUser

 public function testMeReturnsGraphUser()
 {
     $response = (new FacebookRequest(FacebookTestHelper::$testSession, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
     $info = FacebookTestHelper::$testSession->getSessionInfo();
     $this->assertTrue($response instanceof GraphUser);
     $this->assertEquals($info->getId(), $response->getId());
     $this->assertNotNull($response->getName());
     $this->assertNotNull($response->getLastName());
     $this->assertNotNull($response->getLink());
 }
开发者ID:sodacrackers,项目名称:washyacht,代码行数:10,代码来源:GraphUserTest.php

示例13: getGraph

 public function getGraph()
 {
     $request = new FacebookRequest($this->session, 'GET', '/me');
     $response = $request->execute();
     return $response->getGraphObject(GraphUser::className());
     //echo "<img src='$image'/>";
     //echo "<br>";
     //echo "Hello $name <br>";
     //echo "Email: $email <br>";
     //echo "Your Facebook ID: $id <br>";
 }
开发者ID:jeraldpunx,项目名称:3dCakeMaker,代码行数:11,代码来源:FacebookHelper.php

示例14: get_user_information

 public function get_user_information($access_token)
 {
     $session = $this->get_session_from_token($access_token);
     if (!$session->validate()) {
         return false;
     }
     //*** Call api
     $request = new FacebookRequest($session, 'GET', '/me');
     $response = $request->execute();
     return $response->getGraphObject(GraphUser::className());
 }
开发者ID:nguyen-phuoc-mulodo,项目名称:mfb_fuel,代码行数:11,代码来源:facebook.php

示例15: getGraphUser

 /**
  * getUserInfo
  *
  * @throws  FacebookException
  * @return GraphUser
  */
 public function getGraphUser()
 {
     $url = '/me?fields=id,email,first_name,last_name,birthday,permissions';
     try {
         /** @var GraphUser $userProfile */
         $userProfile = (new FacebookRequest($this->session, 'GET', $url))->execute()->getGraphObject(GraphUser::className());
         return $userProfile;
     } catch (FacebookRequestException $e) {
         throw new FacebookException($e->getMessage());
     }
 }
开发者ID:oriodesign,项目名称:tastd-backend-demo,代码行数:17,代码来源:FacebookClient.php


注:本文中的Facebook\GraphUser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。