How to get FB User ID using Facebook Login Button in android application

前端 未结 8 2517
鱼传尺愫
鱼传尺愫 2021-02-05 21:51

I\'m developing an application in which I\'m using Facebook log in button from SDK. I\'m able to get access_token of the user but I want userID

8条回答
  •  星月不相逢
    2021-02-05 22:26

    You should be used new facebook sdk 3.0 and

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
            if (Session.getActiveSession().isOpened()) {
                // Request user data and show the results
                Request.executeMeRequestAsync(Session.getActiveSession(), new Request.GraphUserCallback() {
    
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        // TODO Auto-generated method stub
                        if (user != null) {
                            // Display the parsed user info
                            Log.v(TAG, "Response : " + response);
                            Log.v(TAG, "UserID : " + user.getId());
                            Log.v(TAG, "User FirstName : " + user.getFirstName());
    
                        }
                    }
    
                });
            }
        }
    

提交回复
热议问题