douxi9245
douxi9245
2017-04-14 09:29

PHP / Google OAuth - 获取MAIN Gmail电子邮件而不是@ pages.plusgoogle电子邮件

已采纳

When a user is taken to the authentication page for Google OAuth there are two options, select an account:

https://i.gyazo.com/e58272338236a472f1000b8aa1e426f6.png

or select an account then select a sub-account

https://i.gyazo.com/3e340c41a37f76c20541e1540c902035.png

I want to get the main-gmail account email address email@gmail.com rather than getting their sub YouTube email address such as name-9999@pages.plusgoogle.com

The scopes I use are:

Is there any way I can sort of bypass this or is there another scope I can use outside of this to access their main Gmail.

Edit: After looking through some more posts there was the same issue occurring here: Google OAuth2 Login - Get YouTube nickname and real email address Based back in 2013 quoting:

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.

Does anybody know of further developments relating to this as this would solve the issue aswell

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanca3415 duanca3415 4年前

    To date, there is no possibility to get the gmail address that is associated with a YouTube channel through the YouTube Data API v3. Nothing has changed on this since the answer you quoted was given.

    As @nvnagr said, a YouTube channel is kind of like a distinctive user object, since a Google account can manage multiple YT channels. Otherwise, there is no way to tell which channel you are referring to when making a request. Judging by the referenced question, Google's OAuth system seems to automatically refer to a 'YouTube channel user' instead of a 'real Google user' as soon as you reference any YouTube API-related scopes.

    It might however be possible using the Google+ API. This API has a /people/{userId} endpoint with an emails property.


    Note: Everything beyond this point is just speculation that I made from reading a few documentation pages (meaning I don't know if it works). I figured, however, that it might still help you find a solution.

    When properly authenticating with OAuth 2.0, you can use me for userId to get the respective user's profile representation. According to different parts of the documentation, that either requires the https://www.googleapis.com/auth/plus.me scope (as stated here) or the plus.profile.emails.read scope (stated here, however this one doesn't seem to exist when you prefix it with https://www.googleapis.com/auth/ (click)).

    Depending on what authorization your OAuth token has, you might be able to extract the gmail address from that endpoint, although this looks like it requires a little fiddling around.

    点赞 5 评论 复制链接分享

相关推荐