So I am trying to implement Facebook Login on my Android app.
So far I think it is working. It logins. So, when I go back to my login page (still need to update this) the button I had saying "login with facebook", turns to "Log out".
I press it, but instead of logging out, it logs in again.
This is the code I have for handling Facebook Login
var facebookLoginBtn = findViewById<Button>(R.id.loginFacebookBtn)
facebookLoginBtn.setOnClickListener(View.OnClickListener {
callBackManager = CallbackManager.Factory.create()
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"))
LoginManager.getInstance().registerCallback(callBackManager,
object : FacebookCallback<LoginResult> {
override fun onSuccess(loginResult: LoginResult) {
Log.d("LoginActivity", "Facebook Token: " + loginResult.accessToken.token)
startActivity(Intent(applicationContext, MainActivity::class.java))
}
override fun onCancel() {
Log.d("LoginActivity", "Facebook onCancel")
}
override fun onError(error: FacebookException?) {
Log.d("LoginActivity", "Facebook onError")
}
})
})
}
I tried this for the logout
var btnLogout = findViewById<Button>(R.id.loginFacebookBtn)
btnLogout.setOnClickListener(View.OnClickListener {
if (AccessToken.getCurrentAccessToken() == null) {
return@OnClickListener
} else if (AccessToken.getCurrentAccessToken() != null) {
GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/",
null, HttpMethod.DELETE, GraphRequest.Callback {
LoginManager.getInstance().logOut()
}
).executeAsync()
}
})