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 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名机械工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!
  • ¥20 win11账户锁定时间设为0无法登录
  • ¥45 C#学生成绩管理系统
  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘