douxi9245 2017-04-14 09:29
浏览 394
已采纳

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 2017-04-15 18:24
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错