获取电子邮件,GraphUser与权限 [英] Getting email from GraphUser with Permissions

查看:89
本文介绍了获取电子邮件,GraphUser与权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试登录与下面的code FB。该GraphUser对象有姓,名,ID,但不是电子邮件。我知道我需要添加权限,但我怎么做,在这种情况下。权限一般都加入 Session.OpenRequest 或LogInButton,但我不使用这些。有什么建议?

  Session.openActiveSession(活动,真,新Session.StatusCallback(){
        //回调时,会话状态变化
        @覆盖
        公共无效电话(最后一届会议,SessionState会状态,异常除外){
            如果(session.isOpened()){
                //使请求/我API                Request.newMeRequest(会话,新Request.GraphUserCallback(){
                    //后用户对象图形API响应回调
                    @覆盖
                    公共无效onCompleted(GraphUser用户,响应响应){
                        如果(用户!= NULL){
                            //从GraphUser收到电子邮件
                        }
                    }
                })executeAsync()。
            }
        }
    });


解决方案

只需添加权限作为参数 openActiveSession

  Session.openActiveSession(活动,真实,Arrays.asList(public_profile,电子邮件),新Session.StatusCallback(){
    //回调时,会话状态变化
    @覆盖
    公共无效电话(最后一届会议,SessionState会状态,异常除外){
        如果(session.isOpened()){
            //使请求/我API            Request.newMeRequest(会话,新Request.GraphUserCallback(){
                //后用户对象图形API响应回调
                @覆盖
                公共无效onCompleted(GraphUser用户,响应响应){
                    如果(用户!= NULL){
                        //从GraphUser收到电子邮件
                    }
                }
            })executeAsync()。
        }
    }
});

I'm attempting a log-in with FB with the code below. The GraphUser object has first name, last name, ID, but not email. I know I need to add permissions but how do I do it in this case. The permissions are generally added with Session.OpenRequest or the LogInButton but I'm not using those. Any suggestions?

Session.openActiveSession(activity, true, new Session.StatusCallback() {
        // callback when session changes state
        @Override
        public void call(final Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                // make request to the /me API

                Request.newMeRequest(session, new Request.GraphUserCallback() {
                    // callback after Graph API response with user object
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            // get email from GraphUser
                        }
                    }
                }).executeAsync();
            }
        }
    });

解决方案

Just add the permissions as a parameter in openActiveSession:

Session.openActiveSession(activity, true, Arrays.asList("public_profile", "email"), new Session.StatusCallback() {
    // callback when session changes state
    @Override
    public void call(final Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {
            // make request to the /me API

            Request.newMeRequest(session, new Request.GraphUserCallback() {
                // callback after Graph API response with user object
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        // get email from GraphUser
                    }
                }
            }).executeAsync();
        }
    }
});

这篇关于获取电子邮件,GraphUser与权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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