I need user's email address after successful facebook login in android using SDK 4.0

后端 未结 4 740
深忆病人
深忆病人 2020-12-16 03:47

I have integrated latest Facebook android sdk 4.0. In SDK 3.0+ user\'s email address is retreived using user.getProperty(\"email\") after successful login. I am looking for

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 04:21

    In the new facebook graph you need to ask permissions for access that information. for example on the activity you have put the LoginButton you add this line in the OnCreate method

    loginButtonFacebook.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday"));
    

    Then you get that information

    loginButtonFacebook.registerCallback(callbackManager, new FacebookCallback() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        GraphRequest.newMeRequest(
            loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject me, GraphResponse response) {
                    if (response.getError() != null) {
                        // handle error
                    } else {
                        String email = me.optString("email");
                    }
                }
            }).executeAsync();
    }
    

提交回复
热议问题