Facebook Android SDK 4.5.0 get email address

后端 未结 7 1529
[愿得一人]
[愿得一人] 2020-12-04 16:02

I\'m currently creating a test application to test using the latest facebook SDK to update our existing application problem is that I need to get the email address which I k

7条回答
  •  被撕碎了的回忆
    2020-12-04 16:26

    You can also use GraphResponse object to get the values

    LoginManager.getInstance().registerCallback(callbackManager,
        new FacebookCallback()
        {
            @Override
            public void onSuccess(LoginResult loginResult)
            {
                GraphRequest request = GraphRequest.newMeRequest(
                        loginResult.getAccessToken(),
                        new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject object, GraphResponse response) {
                                Log.v("LoginActivity", response.toString());
                                try {
                                    // Application code
                                    String email = response.getJSONObject().getString("email");
                                    txtStatus.setText("Login Success \n" + email);
                                }catch(Exception e){
                                    e.printStackTrace();;
                                }
                            }
                        });
                Bundle parameters = new Bundle();
                parameters.putString("fields", "id,name,email,gender,birthday");
                request.setParameters(parameters);
                request.executeAsync();
            }
    
            @Override
            public void onCancel()
            {
                txtStatus.setText("==============Login Cancelled=============");
            }
    
            @Override
            public void onError(FacebookException exception)
            {
                txtStatus.setText("==============Login Error=================");
                exception.printStackTrace();
            }
        });
    

提交回复
热议问题