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

前端 未结 8 2512
鱼传尺愫
鱼传尺愫 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:46
    loginResult.getAccessToken().getUserId()
    
    0 讨论(0)
  • 2021-02-05 22:46

    Based on answer from @Ketan Mehta (https://stackoverflow.com/a/17397931/624109) that uses a deprecated API, you should use the following code:

    @Override
    public 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.newMeRequest(Session.getActiveSession(), new GraphUserCallback()
            {
                @Override
                public void onCompleted(GraphUser user, Response response)
                {
                    if (null != user)
                    {
                        // Display the parsed user info
                        Log.v(TAG, "Response : " + response);
                        Log.v(TAG, "UserID : " + user.getId());
                        Log.v(TAG, "User FirstName : " + user.getFirstName());
    
                    }
                }
            }).executeAsync();
        }
    }
    
    0 讨论(0)
提交回复
热议问题