I am using HWIOAuthBundle for retrieving data from google+ api. For that, I extended FOSUBUserProvider class and I rewrote the public function loadUserByOAuthUserResponse(UserResponseInterface $response) {}
as follows:
public function loadUserByOAuthUserResponse(UserResponseInterface $response) {
// some check
// ...
// getting the attributes for the google+ api
$attr = $response->getResponse();
// creating and setting my user
$user = $this->userManager->createUser();
$user->$setter_id($username);
$user->$setter_token($response->getAccessToken());
$user->setEmail($response->getEmail());
$user->setEmailCanonical($response->getEmail());
if (isset($attr['gender'])) {
if ($attr['gender'] == 'male')
$user->setGoogleGender(true);
else
$user->setGoogleGender(false);
}
if (isset($attr['birthday'])) {
$user->setGoogleBirthday(new \DateTime($attr['birthday']));
}
if (isset($attr['name'])) {
// $attr['name'] contains displayName (givenName and familyName together)
}
return $user;
}
This is how is defined the person in google+.
{
"kind": "plus#person",
"etag": "XXXX",
"gender": "male",
"objectType": "person",
"id": "9999999999999",
"displayName": "Jule Dupond",
"name": {
"familyName": "Dupond",
"givenName": "Jule"
},
"url": "https://plus.google.com/9999999",
"image": {
"url": "https://....",
"isDefault": true
},
"isPlusUser": true,
"circledByCount": 1,
"verified": false
}
My goal is simply to retrieve givenName
and familyName
.
Thank you for giving me an idea!
I found the solution. To get familyName and givenName, you just need this: $attr['given_name']
and $attr['family_name']
.
Hope it will help others...