/** * 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; }
/** * 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; }