1

这是我的 facebook me request 代码。我想获取用户电子邮件和其他基本信息。此代码在模拟器中没有任何问题。但在真实设备中,电子邮件给出了 null 值。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();
4

1 回答 1

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", ...));
于 2014-01-03T20:00:21.093 回答