Facebook android SDK 3从用户那里获得电子邮件

时间:2013-05-17 13:18:02

标签: android facebook

这是我的facebook me request.i想要获取用户电子邮件和其他基本信息的代码。这个代码在模拟器中没有任何问题。但在真实设备中,电子邮件给出了空值。 id,fristname ......带有真正的价值。我怎样才能在真实设备上收到电子邮件?

    Request request = Request.newMeRequest(session,
            new Request.GraphUserCallback() {


                @Override
                public void onCompleted(GraphUser user, Response response) {

                    if (user != null) {



                        RequestParams params = new RequestParams();

                        params.put("email",(String) user.getProperty("email"));
                        params.put("password", "");
                        params.put("facebook_id", user.getId());
                        editor.putString("facebook_id", user.getId());

                        login(params,
                                (String) user.asMap().get("email"),
                                user.getId(), user.getFirstName(),
                                user.getLastName());

                    }
                }
            });
    Bundle params = new Bundle();
    params.putString("fields", "id,email,first_name,last_name");
    request.setParameters(params);
    request.executeAsync();

1 个答案:

答案 0 :(得分:2)

不是提交ME请求,而是使用Facebook的LoginButton,并添加一个钩子来拦截用户信息:

// Intercept the facebook user returned from login
facebookLoginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {

    @Override
    public void onUserInfoFetched(GraphUser user) {
        mFacebookUser = user;

        if (user != null) {
            LogUtils.LOGFB(TAG, "Got a Facebook user: " + user.getFirstName() +
                    " " + user.getLastName() + ", email: " + user.getProperty("email"));
        }
        else {
            LogUtils.LOGFB(TAG, "No Facebook user");
        }
    }
});

然后添加额外的权限以获取电子邮件:

facebookLoginButton.setReadPermissions(Arrays.asList(
        "email", "user_birthday", ...));