如何使用 hwioauthBundle 在 oauth2 之后获取 google 帐户电子邮件地址

How to get google account email address after oauth2 using the hwioauthBundle

如何访问用户的电子邮件地址。我正在使用内置的 hwi_oauth.user.provider

最好的方法是什么?

这是我的 config.yml

    resource_owners:
    google:
        type:                google
        client_id:           <CLIENTID>
        client_secret:       <SECRET>
        scope:               "email profile https://spreadsheets.google.com/feeds https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.login"
        paths:
            email:           email

这是我的 security.yml

security:

# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
    in_memory:
        memory: ~
    hwi:                               
        id: hwi_oauth.user.provider
firewalls:
    secured_area:           
       anonymous: ~
       oauth:
           resource_owners:                   
               google:             "/login/check-google"
           login_path:        /login
           use_forward:       false
           failure_path:      /login

           oauth_user_provider:
               service: hwi_oauth.user.provider
       logout:
           path: /logout
           target: /
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~

我不知道,但一年前我正在使用 HWIOauth,我的配置如下:

google:
            type:                google
            client_id:           client_id
            client_secret:       secret
            scope:               "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"

它 returns 发邮件给我。但也许 google 改变一些我不知道的东西,希望这会有所帮助 :)