如何使用Grails社交插件从Facebook获取电子邮件ID [英] How to get email id from facebook using Grails social plugin

查看:131
本文介绍了如何使用Grails社交插件从Facebook获取电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了 spring-security-oauth-facebook:0.1 grails插件。现在我想访问个人的电子邮件ID,但每次facebook服务器都无法响应 1829812989120 for socialId,Username,profileId,并且在返回Map对象时没有电子邮件选项。为什么发生这种情况。

I am using spring-security-oauth-facebook:0.1 grails plugin in my application.Now i want to access person's email id but i am not able each time facebook server respond 1829812989120 for socialId ,Username, profileId and there is no option of email in returning Map object.Why it is happening.

     oauth {
        debug = true
           providers {
    facebook {
        api = org.scribe.builder.api.FacebookApi
        key = 'my-app-key'
        secret = 'secret-key'
        successUri = '/oauth/facebook/success'
        failureUri = '/oauth/facebook/failure'
        callback = "${baseURL}/oauth/facebook/callback"
        scopes = "['public_profile','email','name','user']"

      } 

    def sessionKey = oauthService.findSessionKeyForAccessToken(provider)

    if (!session[sessionKey]) {
        log.warn "No OAuth token in the session for provider '${provider}'"
        throw new OAuthLoginException("Authentication error for provider '${provider}'")
    }
    // Create the relevant authentication token and attempt to log in.

    OAuthToken oAuthToken = springSecurityOAuthService.createAuthToken(provider, 
                                                                            session[sessionKey])
    println "oAuthToken.principal = "+oAuthToken.principal.toString();
    println "oAuthToken.socialId  = "+oAuthToken.socialId;
    println "oAuthToken.properties= "+oAuthToken.properties
    println "oAuthToken.properties= "+oAuthToken.name
    println "oAuthToken.properties= "+oAuthToken.toString();

1)我把所有的println值email都不存在。
请帮助我如何获取登录用户的电子邮件地址。

1)I ckecked all println value email is not there. please help me how to get email address of logged in user.

推荐答案

在创建会话后使用此代码

Use this code after session created

OAuthToken oAuthToken = springSecurityOAuthService.createAuthToken(provider, 
                                                                        session[sessionKey])
Token facebookAccessToken = (Token) session[oauthService.findSessionKeyForAccessToken('facebook')]

println "Facebook token :"+facebookAccessToken

def facebookResource = oauthService.getFacebookResource(facebookAccessToken ,    "https://graph.facebook.com/me")

def facebookResponse = JSON.parse(facebookResource?.getBody())

这篇关于如何使用Grails社交插件从Facebook获取电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆