Android Facebook SDK 4.X , how to get Email address and Facebook Access Token to pass it to Web Service

前端 未结 3 1532
情深已故
情深已故 2020-12-09 00:07

EDIT : My Question is how to get Email , UserId , Facebook Authentication with Facebook SDK 4.X , at this moment , with Ming Respond , i know how can i get Email , User Id

3条回答
  •  一个人的身影
    2020-12-09 00:53

    fbLoginBtn.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");
                            String id = me.optString("id");
                            // send email and id to your web server
                        }
                    }
                }).executeAsync();
        }
    
        @Override
        public void onCancel() {
            // App code
        }
    
        @Override
        public void onError(FacebookException exception) {
            // App code
        }
    });
    

提交回复
热议问题