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 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题