Example #1
0
 /**
  * Returns user profile
  *
  * Examples:
  *
  *	$data = $hybridauth->authenticate( "Facebook" )->getUserProfile();
  */
 function getUserProfile()
 {
     // request user infos
     $response = $this->signedRequest("me");
     $response = json_decode($response);
     if (!isset($response->id) || isset($response->error)) {
         throw new Exception('User profile request failed: Provider returned an invalid response. ' . 'HTTP client state: (' . $this->httpClient->getState() . ')', Exception::USER_PROFILE_REQUEST_FAILED, $this);
     }
     $parser = function ($property) use($response) {
         return property_exists($response, $property) ? $response->{$property} : null;
     };
     $profile = new Profile();
     $profile->setIdentifier($parser('id'));
     $profile->setFirstName($parser('first_name'));
     $profile->setLastName($parser('last_name'));
     $profile->setDisplayName($parser('name'));
     $profile->setProfileURL($parser('link'));
     $profile->setWebSiteURL($parser('website'));
     $profile->setGender($parser('gender'));
     $profile->setDescription($parser('bio'));
     $profile->setEmail($parser('email'));
     $profile->setLanguage($parser('locale'));
     $profile->setPhotoURL('https://graph.facebook.com/' . $profile->getIdentifier() . '/picture?width=150&height=150');
     if ($parser('birthday')) {
         list($m, $d, $y) = explode("/", $parser('birthday'));
         $profile->setBirthDay($d);
         $profile->setBirthMonth($m);
         $profile->setBirthYear($y);
     }
     if ($parser('verified')) {
         $profile->setEmailVerified($profile->getEmail());
     }
     return $profile;
 }
Example #2
0
 /**
  * Returns user profile
  *
  * Examples:
  *
  *	$data = $hybridauth->authenticate( "Windows" )->getUserProfile();
  */
 function getUserProfile()
 {
     $response = $this->signedRequest("me");
     $response = json_decode($response);
     if (!isset($response->id) || isset($response->error)) {
         throw new Exception('User profile request failed: Provider returned an invalid response. ' . 'HTTP client state:(' . $this->httpClient->getState() . ')', Exception::USER_PROFILE_REQUEST_FAILED, $this);
     }
     $parser = function ($property) use($response) {
         return property_exists($response, $property) ? $response->{$property} : null;
     };
     $profile = new Profile();
     $profile->setIdentifier($parser('id'));
     $profile->setFirstName($parser('first_name'));
     $profile->setLastName($parser('last_name'));
     $profile->setDisplayName($parser('name'));
     $profile->setProfileURL($parser('link'));
     $profile->setWebSiteURL($parser('website'));
     $profile->setGender($parser('gender'));
     $profile->setLanguage($parser('locale'));
     $profile->setEmail($response->emails->account);
     //< this
     $profile->setBirthDay($parser('birth_day'));
     $profile->setBirthMonth($parser('birth_month'));
     $profile->setBirthYear($parser('birth_year'));
     return $profile;
 }
Example #3
0
 /**
  * Returns user profile
  *
  * Examples:
  *
  *	$data = $hybridauth->authenticate( "Twitter" )->getUserProfile();
  */
 function getUserProfile()
 {
     $response = $this->signedRequest('account/verify_credentials.json');
     $response = json_decode($response);
     if (!isset($response->id) || isset($response->error)) {
         throw new Exception('User profile request failed: Provider returned an invalid response. ' . 'HTTP client state: (' . $this->httpClient->getState() . ')', Exception::USER_PROFILE_REQUEST_FAILED, $this);
     }
     $parser = function ($property) use($response) {
         return property_exists($response, $property) ? $response->{$property} : null;
     };
     $profile = new Profile();
     $profile->setIdentifier($parser('id'));
     $profile->setFirstName($parser('name'));
     $profile->setDisplayName($parser('screen_name'));
     $profile->setDescription($parser('description'));
     $profile->setPhotoURL($parser('profile_image_url'));
     $profile->setWebSiteURL($parser('url'));
     $profile->setRegion($parser('location'));
     $profile->setProfileURL('http://twitter.com/' . $profile->getDisplayName());
     return $profile;
 }
Example #4
0
 /**
  * Returns user contacts list
  *
  * Examples:
  *
  *	$data = $hybridauth->authenticate( "Google" )->getUserContacts( array( "max-results" => 10 ) );
  */
 function getUserContacts($args = array())
 {
     // refresh tokens if needed
     $this->refreshToken();
     $url = "https://www.google.com/m8/feeds/contacts/default/full?" . http_build_query(array_merge(array('alt' => 'json'), $args));
     $response = $this->signedRequest($url);
     $response = json_decode($response);
     if (!$response || isset($response->error)) {
         throw new Exception('User contacts request failed: Provider returned an invalid response. ' . 'HTTP client state: (' . $this->httpClient->getState() . ')', Exception::USER_PROFILE_REQUEST_FAILED, $this);
     }
     $contacts = array();
     if (isset($response->feed) && is_array($response->feed)) {
         foreach ($response->feed->entry as $idx => $entry) {
             $profile = new Profile();
             $email = isset($entry->{'gd$email'}[0]->address) ? (string) $entry->{'gd$email'}[0]->address : '';
             $displayName = isset($entry->title->{'$t'}) ? (string) $entry->title->{'$t'} : '';
             $profile->setIdentifier($email);
             $profile->setDisplayName($displayName);
             $profile->setEmail($email);
             $contacts[] = $profile;
         }
     }
     return $contacts;
 }