我正在尝试在我的 android 应用程序中使用 Facebook AccountKit 。
这是我的代码:
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);
}
这是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();
}
}
MainActivity
当我通过 SMS 获取验证码并输入该代码并打开成功吐司时,一切都很好。
但是在我的 中MainActivity
,我正在使用以下代码:
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();
}
如果为空,它会导航回SignUp屏幕accessToken
,这就是正在发生的事情给我这个错误:com.facebook.accountkit.internal.LoginManager: No access token: cannot retrieve account
这也在logcat中打印出来:AccountKitError: 400: An internal consistency error has occurred: 406: No access token: cannot retrieve account
这里出了什么问题?为什么我无法在accessToken
这里获得?