예제 #1
1
 /**
  * Return info about facebook user
  * @param $fields
  * @return array
  * @throws Exception
  */
 public function getMe($fields)
 {
     $client = $this->fb->getOAuth2Client();
     $accessTokenObject = $this->helper->getAccessToken();
     if ($accessTokenObject == null) {
         throw new Exception("User not allowed permissions");
     }
     if ($fields == "" || !is_array($fields) || count($fields) == 0) {
         //array is empty
         $fields = array(ID);
         //set ID field
     }
     try {
         $accessToken = $client->getLongLivedAccessToken($accessTokenObject->getValue());
         $response = $this->fb->get("/me?fields=" . implode(",", $fields), $accessToken);
         $this->setSocialLoginCookie(self::SOCIAL_NAME);
         return $response->getDecodedBody();
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         // When Graph returns an error
         throw new Exception($e->getMessage());
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         // When validation fails or other local issues
         throw new Exception($e->getMessage());
     }
 }
예제 #2
0
 /**
  * Return info about login user
  * @return array
  * @throws Exception
  */
 public function getMe()
 {
     $client = $this->fb->getOAuth2Client();
     $accessTokenObject = $this->helper->getAccessToken();
     if ($accessTokenObject == null) {
         throw new Exception("User not allowed permissions");
     }
     try {
         $accessToken = $client->getLongLivedAccessToken($accessTokenObject->getValue());
         $response = $this->fb->get('/me?fields=id,name,email', $accessToken);
         return $response->getDecodedBody();
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         // When Graph returns an error
         throw new Exception($e->getMessage());
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         // When validation fails or other local issues
         throw new Exception($e->getMessage());
     }
 }