Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
485 views
Welcome To Ask or Share your Answers For Others

1 Answer

Interesting use case. Unfortunately there is no way to do this with one token at this time. The reason is that youtube channel is represented by a different object (almost like a user account) in the system. And an OAuth grant can belong to either the gmail user or the youtube channel. When we see the youtube scope in the request, we show a list of user id and any channels that the user may have and the approving user selects one of them. And the resulting token belongs to that object/account.

We are building new features related to delegation and channels. e.g. One possible solution may be to get a single token on the user account that gives you access to APIs on all channels that are managed by that account. Sorry, there is no ETA at this time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...