Is there any way to get the users youtube nickname together with his REAL (*@gmail.com) email address?
Whenever I ask google to authenticate the user with "youtube.readonly" scope, the email address changes to "*@pages.plusgoogle.com". But when I leave out the YouTube scope I do not get the YouTube nickname...
Requests performed by Google API PHP Client (https://github.com/google/google-api-php-client)
Examples
1. Right email / Wrong name:
Scopes:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
Userinfo:
email: "********@gmail.com" //<- I need this
family_name: <My last name>
given_name: <My first name>
name: <My full name>
verified_email: true
[...]
2. Wrong email / Right name:
Scopes:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/youtube.readonly
Userinfo:
email: "<My YT nickname>-<Random(?) ID>@pages.plusgoogle.com"
family_name: "."
given_name: <My YT nickname>
name: <My YT nickname> //<- and I need that
verified_email: true
[...]
So: How to get the email from request #1 and the name of request #2 without changing the scopes (what requires re-authentication)?
Code
$oauth2 = new Google_Service_Oauth2($google);
if (strlen($code) > 10) {
try {
$accessToken = $google->authenticate($code);
} catch (Google_Auth_Exception $e) {
return new false;
}
if (!$accessToken) {
return false;
}
$userinfo = $oauth2->userinfo->get();
var_dump($userinfo);die;
}
Dump (with YT scope)
object(Google_Service_Oauth2_Userinfo)[325]
public 'email' => string '***@pages.plusgoogle.com' (length=36) //wrong email..
public 'family_name' => string '.' (length=1)
public 'gender' => null
public 'given_name' => string '***' (length=10)
public 'hd' => null
public 'id' => string '1013***' (length=21)
public 'link' => string 'https://plus.google.com/1013***' (length=45)
public 'locale' => null
public 'name' => string '***' (length=10)
public 'picture' => string 'https://lh5.googleusercontent.com/***/photo.jpg' (length=92)
public 'timezone' => null
public 'verified_email' => boolean true
protected 'data' =>
array (size=0)
empty
protected 'processed' =>
array (size=0)
empty
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…