Reputation: 2959
I'm trying to use Facebook AccountKit in my android app.
Here's my code:
loginPhoneNumber.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
phoneLogin(view);
}
});
public void phoneLogin(final View view) {
final Intent intent = new Intent(getBaseContext(), AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(
LoginType.PHONE,
AccountKitActivity.ResponseType.CODE); // or .ResponseType.TOKEN
// ... perform additional configuration ...
intent.putExtra(
AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
configurationBuilder.build());
startActivityForResult(intent, APP_REQUEST_CODE);
}
here's onActivityResult()
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
if (requestCode == APP_REQUEST_CODE) { // confirm that this response matches your request
AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
String toastMessage;
if (loginResult.getError() != null) {
toastMessage = loginResult.getError().getErrorType().getMessage();
} else if (loginResult.wasCancelled()) {
toastMessage = "Login Cancelled";
} else {
if (loginResult.getAccessToken() != null) {
toastMessage = "Success:" + loginResult.getAccessToken().getAccountId();
} else {
toastMessage = String.format(
"Success: ",
loginResult.getAuthorizationCode());
}
// If you have an authorization code, retrieve it from
// loginResult.getAuthorizationCode()
// and pass it to your server and exchange it for an access token.
// Success! Start your next activity...
Intent intent = new Intent(SignUpActivity.this, MainActivity.class);
startActivity(intent);
}
// Surface the result to your user in an appropriate way.
Toast.makeText(
this,
toastMessage,
Toast.LENGTH_LONG)
.show();
}
}
Everything is happening fine to the point when I get the verification code through SMS and I type in that code and MainActivity
gets opened the success toast appears.
But in my MainActivity
, I am using this code:
com.facebook.accountkit.AccessToken accessToken = AccountKit.getCurrentAccessToken();
if (accessToken != null) {
//Handle Returning User
Toast.makeText(getBaseContext(), "Hello", Toast.LENGTH_SHORT).show();
} else {
//Handle new or logged out user
Intent intent = new Intent(MainActivity.this, SignUpActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
Toast.makeText(getBaseContext(), "sent from 1", Toast.LENGTH_SHORT).show();
}
which navigates back to SignUp screen if the accessToken
is null and that is what's happening giving me this error: com.facebook.accountkit.internal.LoginManager: No access token: cannot retrieve account
and this is also getting printed out in logcat: AccountKitError: 400: An internal consistency error has occurred: 406: No access token: cannot retrieve account
What's going wrong here? Why am I unable to get an accessToken
here?
Upvotes: 1
Views: 683
Reputation: 36
If you want to use access token in Account Kit, you'll want to change the configuration build use AccountKitActivity.ResponseType.TOKEN
and not AccountKitActivity.ResponseType.CODE
Upvotes: 1