Login Google OAuth2 - Uzyskaj pseudonim YouTube i prawdziwy adres e-mail
Czy jest jakiś sposób, aby uzyskać pseudonim użytkownika youtube wraz z jego adresem e-mail REAL (*@gmail.com)?
Kiedy pytam google o uwierzytelnienie użytkownika za pomocą zakresu „youtube.readonly”, adres e-mail zmienia się na „*@ pages.plusgoogle.com ". Ale gdy opuszczę zakres YouTube, nie otrzymam pseudonimu YouTube ...
Żądania wykonywane przez klienta Google API PHP (https://github.com/google/google-api-php-client)
Przykłady1. Prawy e-mail / Zła nazwa:
Zakresy:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
Informacje użytkownika:
email: "********@gmail.com" //<- I need this
family_name: <My last name>
given_name: <My first name>
name: <My full name>
verified_email: true
[...]
2. Błędny e-mail / Prawidłowa nazwa:
Zakresy:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/youtube.readonly
Informacje użytkownika:
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
[...]
Więc: Jak uzyskać wiadomość e-mail z żądania nr 1 i nazwę żądania nr 2 bez zmiany zakresów (co wymaga ponownego uwierzytelnienia)?
Kod$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;
}
Wysypisko (z zakresem YT)
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