如何在 GraphRequest.newMeRequest 上获取用户电子邮件 [英] How to get user email on GraphRequest.newMeRequest

查看:32
本文介绍了如何在 GraphRequest.newMeRequest 上获取用户电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android 应用程序中有 Facebook 登录选项,但我尝试获取用户的电子邮件失败.用户登录并添加到 Parse.com 用户表(使用有效的访问令牌)后,我请求 Facebook 用户信息,但只获取它的 ID 和名称(即使电子邮件被设置为权限之一).

I have a Facebook login option in my Android app and I am trying to get the user's email unsuccessfully. After the user is logged in, and added to the Parse.com User table (with a valid access token), I request the Facebook user info, but only get it's id and name (even though the email is set as one of the permissions).

这是我的代码(在我的按钮的 OnClickListener 中):

Here's my code (inside OnClickListener of my button):

ParseFacebookUtils.logInWithReadPermissionsInBackground(
    getActivity(), Arrays.asList("email", "user_friends"), new LogInCallback() {
        @Override
        public void done(ParseUser user, ParseException err) {
            //err is null

            if (user == null) {
                Log.d(TAG, "Uh oh. The user cancelled the Facebook login.");
            } else {
                GraphRequest.newMeRequest(
                    AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject user, GraphResponse response) {

                            Log.d(TAG, "user = " + user.toString());
                            //prints -> user = {"name":"my_fb_name","id":"my_fb_id"}
                        }
                    }
                ).executeAsync();                
           }
       });

推荐答案

我猜这与 Graph API v2.4 中的更改有关,这使得您必须指定要从 Graph API 返回的每个字段.

I guess this is related to a change in the Graph API v2.4 which makes it necessary that you specify every field you want to have returned from the Graph API.

看看我在

关于这个

关于您的实际问题,请参阅

Concerning your actual problem, see

有关如何为 GraphRequest

GraphRequest request = GraphRequest.newMeRequest(
        accessToken,
        new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(
                   JSONObject object,
                   GraphResponse response) {
                // Application code
            }
        });
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();

这篇关于如何在 GraphRequest.newMeRequest 上获取用户电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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