0

i've implemented the facebook auth now i want to get the email , username , date of birth in the app of that user FB module https://github.com/betranthanh/android-kotlin-loginfacebook

1 Answers1

0

I found solution for my own problem it looks something like this

this is my onClick listener of FB loginButton

'fun facebook(view: View) {

    callbackManager = CallbackManager.Factory.create()
    Profile.getCurrentProfile()

    LoginManager.getInstance().registerCallback(callbackManager,
        object : FacebookCallback<LoginResult> {
            override fun onSuccess(loginResult: LoginResult) {

                handleFacebookToken(AccessToken.getCurrentAccessToken())

               // Log.d("MainActivity", "Facebook token: " + loginResult.accessToken.token)
               // Log.d("MainActivity", "Facebook id: "  + loginResult.accessToken.userId)
                startActivity(Intent(applicationContext, LoginActivity::class.java))


            }

            override fun onCancel() {
                Log.d("MainActivity", "Facebook onCancel.")

            }

            override fun onError(error: FacebookException) {
                Log.d("MainActivity", "Facebook onError.")

            }
        })
}

//this is my FacebookHandler `private fun handleFacebookToken(accessToken: AccessToken) { val profile = Profile.getCurrentProfile() if (profile != null){

       val firstName = profile.firstName
        val lastname = profile.middleName
        val email = profile.id

        Log.d("MainActivity","first name : $firstName")
        Log.d("MainActivity","full name : $lastname")
        Log.d("MainActivity","id : $email")
        idName.setText(firstName)

    }
}`