I am using this page code:https://github.com/google/google-api-php-client/blob/a88dcec6833ac2de4798c13a24abe30c90feb057/examples/idtoken.php to get email address and givenName and familyName from Google for Google sign in purpose.
If I'm setting the scope to email
I do get the email stored in Google account (not the one in Google plus). If I'm setting the scope to 'profile' I do get the givenName and familyName stored in Google not in Google plus profile. I need this name because most users don't have a Google Plus profile.
I tried combining them but I get either email or Name, never both.
- I tried
$client->setScopes('profile','email');
-- it only brings Name, not email - I tried
$client->setScopes('email','profile');
-- it only brings email, and Name fields are empty. - I also tried to set using
$google_client->setScopes(array('https://www.googleapis.com/auth/plus.login'));
like here: How to get user details corectly with google api but only gets one or the other, never both. It's like the setScopes doesn't add the scopes, but uses only the first in the list.
This is the code used:
$_SESSION['access_token'] = $client->getAccessToken();
$token_data = $client->verifyIdToken()->getAttributes();
$oAuth2 = new Google_Service_Oauth2($client);
$oAttr = $oAuth2->userinfo->get();
$test_me = $oAuth2->userinfo_v2_me->get();;
/* the next part doesn't bring names or emails because the user doesn't have g+
$plus = new Google_Service_Plus($client);
$me = $plus->people->get('me');
$firstname = $me['name']['givenName'];
$lastname = $me['name']['familyName'];
*/
Any idea what's the proper way to combine profile and email in the setScopes to get both email and names?
Thanks.