400:发生内部一致性错误: 406:无访问令牌:无法检索帐户
400: An internal consistency error has occurred: 406: No access token: cannot retrieve account
当我尝试在 phone 验证
之后准确获取访问令牌时抛出错误
phoneLogin() this method load the UI and all the process goes perfect but when i try
`if (loginResult.getAccessToken() != null) {
Log.e("token", loginResult.getAccessToken().toString());
toastMessage = "Success:" + loginResult.getAccessToken().getAccountId();
}
` 下面提到了它抛出错误的这段代码
错误:400: An internal consistency error has occurred: 406: No access token: cannot retrieve account
代码
public void phoneLogin() {
final Intent intent = new Intent(LoginActivity.this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(
LoginType.PHONE,
AccountKitActivity.ResponseType.CODE); // or .ResponseType.TOKEN
UIManager uiManager = new SkinManager(SkinManager.Skin.CLASSIC, Color.GRAY, R.drawable.bubble_background, SkinManager.Tint.BLACK, 5);
configurationBuilder.setUIManager(uiManager);
// ... perform additional configuration ...
intent.putExtra(
AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
configurationBuilder.build());
startActivityForResult(intent, APP_REQUEST_CODE);
}
@Override
protected void onActivityResult(
final int requestCode,
final int resultCode,
final Intent data) {
super.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();
// showErrorActivity(loginResult.getError());
Log.e("error", loginResult.getError().toString());
} else if (loginResult.wasCancelled()) {
toastMessage = "Login Cancelled";
} else {
if (loginResult.getAccessToken() != null) {
Log.e("token", loginResult.getAccessToken().toString());
toastMessage = "Success:" + loginResult.getAccessToken().getAccountId();
} else {
toastMessage = String.format(
"Success:%s...",
loginResult.getAuthorizationCode().substring(0, 10));
}
// 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...
// goToMyLoggedInActivity();
Log.d("success", toastMessage);
Toast.makeText(this, "success", Toast.LENGTH_LONG).show();
try {
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(Account account) {
String accountKitId = account.getId();
// Get phone number
PhoneNumber phoneNumber = account.getPhoneNumber();
String phoneNumberString = phoneNumber.toString();
SessionManager sessionManager = new SessionManager(getApplicationContext());
sessionManager.setPhone(phoneNumberString);
startActivity(new Intent(LoginActivity.this, MobileVerification.class));
finish();
}
@Override
public void onError(AccountKitError accountKitError) {
}
});
} catch (Exception e) {
Log.d("catch", e.toString());
}
}
// Surface the result to your user in an appropriate way.
}
public void goToLogin(boolean isSMSLogin) {
LoginType loginType = isSMSLogin ? LoginType.PHONE : LoginType.EMAIL;
final Intent intent = new Intent(this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(
loginType,
AccountKitActivity.ResponseType.TOKEN);
UIManager uiManager = new SkinManager(
SkinManager.Skin.CONTEMPORARY,
getResources().getColor(R.color.colorBackground),
R.drawable.bg,
SkinManager.Tint.BLACK,
0.10);
configurationBuilder.setUIManager(uiManager);
intent.putExtra(
AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
configurationBuilder.build());
this.startActivityForResult(intent, APP_REQUEST_CODE);
}
public void smsLogin(View v){
goToLogin(true);
}
public void emailLogin(View v){
goToLogin(false);
}
private void goToMyLoggedInActivity(){
final Intent intent = new Intent(this, SecondActivity.class);
this.startActivity(intent);
}
private void logAssert(String error) {
Log.println(Log.ASSERT, "AccountKit", error);
}
}
只是改变AccountKitActivity.ResponseType.CODE);至 AccountKitActivity.ResponseType.TOKEN);
您必须先登录才能获得访问令牌。
public void phoneLogin(final View view) {
final Intent intent = new Intent(getActivity(), 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);
}
https://developers.facebook.com/docs/accountkit/android#smslogin
第一次你没有访问令牌,这意味着你重定向到移动验证 Screen.Class 并在获得访问令牌后你重定向到 HomeActivity.class 并在共享首选项中存储令牌在终止应用程序时曾经打开应用程序然后重定向到 LoginActivity.class
if (sessionManager.isLoggedIn() && accessToken != null) {
startActivity(new Intent(SplashActivity.this,LoginActivity.class ));
} else {
startActivity(new Intent(SplashActivity.this,Mobile Verfication.class ));
}
你已经把一切都做得很完美了只是改变AccountKitActivity.ResponseType.CODE); to AccountKitActivity.ResponseType.TOKEN);
i have to make demo for You and i successfully Logined with Facebbok accountKit(here not Applying With Permisson):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:backgroundTint="#FFFFFF"
android:background="#FFFFFF">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:backgroundTint="#FFFFFF">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_vertical|center_horizontal"
android:layout_weight=".25"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login with AccountKit"
android:id="@+id/textView6"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:gravity="top|center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="This example shows you how to implement Facebook AccountKit in Android using Java."
android:id="@+id/textView7"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".07"
android:gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Login with Email"
android:id="@+id/button"
android:onClick="emailLogin"
android:backgroundTint="#4E86FF"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".07"
android:gravity="center_horizontal"
android:layout_marginBottom="150dp">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Login with Phone"
android:id="@+id/button2"
android:onClick="smsLogin"
android:backgroundTint="#4E86FF"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
InitialActivity.java:
public class InitialActivity extends AppCompatActivity {
public static int APP_REQUEST_CODE = 99;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AccountKit.initialize(getApplicationContext());
setContentView(R.layout.activity_initial);
AccessToken accessToken = AccountKit.getCurrentAccessToken();
Log.d("accesssToken:----",""+accessToken);
if(accessToken != null){
goToMyLoggedInActivity();
}
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == APP_REQUEST_CODE) { // confirm that this response matches your request
AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
String responseMessage;
if (loginResult.getError() != null) {
responseMessage = loginResult.getError().getErrorType().getMessage();
logAssert(loginResult.getError() + " - " + responseMessage);
} else if (loginResult.wasCancelled()) {
responseMessage = "Login Cancelled";
logAssert(responseMessage);
} else {
if (loginResult.getAccessToken() != null) {
Log.d("Token:-",""+loginResult.getAccessToken());
responseMessage = "Success: " + loginResult.getAccessToken().getAccountId();
logAssert(responseMessage);
} else {
responseMessage = String.format(
"Success:%s...",
loginResult.getAuthorizationCode().substring(0,10));
logAssert(responseMessage);
}
// 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...
goToMyLoggedInActivity();
}
}
}
public void goToLogin(boolean isSMSLogin) {
LoginType loginType = isSMSLogin ? LoginType.PHONE : LoginType.EMAIL;
final Intent intent = new Intent(this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(
loginType,
AccountKitActivity.ResponseType.TOKEN);
UIManager uiManager = new SkinManager(
SkinManager.Skin.CONTEMPORARY,
getResources().getColor(R.color.colorBackground),
R.drawable.bg,
SkinManager.Tint.BLACK,
0.10);
configurationBuilder.setUIManager(uiManager);
intent.putExtra(
AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
configurationBuilder.build());
this.startActivityForResult(intent, APP_REQUEST_CODE);
}
public void smsLogin(View v){
goToLogin(true);
}
public void emailLogin(View v){
goToLogin(false);
}
private void goToMyLoggedInActivity(){
final Intent intent = new Intent(this, SecondActivity.class);
this.startActivity(intent);
}
private void logAssert(String error) {
Log.println(Log.ASSERT, "AccountKit", error);
}
}
Second Activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_second" />
</android.support.design.widget.CoordinatorLayout>
SecondActivity.java:
public class SecondActivity extends AppCompatActivity {
TextView txtAccountKitID, txtUserLoginMode, txtUserLoginData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
txtAccountKitID = (TextView) findViewById(R.id.txtAccountKitID);
txtUserLoginMode = (TextView) findViewById(R.id.txtUserLoginMode);
txtUserLoginData = (TextView) findViewById(R.id.txtUserLoginData);
this.setUserInformation();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public void setUserInformation(){
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(final Account account) {
// Get Account Kit ID
String accountKitId = account.getId();
logAssert("ID: " + accountKitId);
boolean SMSLoginMode = false;
// Get phone number
PhoneNumber phoneNumber = account.getPhoneNumber();
String phoneNumberString = "";
if (phoneNumber != null) {
phoneNumberString = phoneNumber.toString();
logAssert("Phone: " + phoneNumberString);
SMSLoginMode = true;
}
// Get email
String email = account.getEmail();
logAssert("Email: " + email);
txtAccountKitID.setText(accountKitId);
txtUserLoginMode.setText(SMSLoginMode ? "Phone:" : "Email:");
if (SMSLoginMode) {
txtUserLoginData.setText(phoneNumberString);
} else {
txtUserLoginData.setText(email);
}
}
@Override
public void onError(final AccountKitError error) {
logAssert("Error: " + error.toString());
}
});
}
public void LogOut(View v){
AccountKit.logOut();
Intent initialActivity = new Intent(this, InitialActivity.class);
this.startActivity(initialActivity);
this.finish();
}
private void logAssert(String error) {
Log.println(Log.ASSERT, "AccountKit", error);
}
}
Android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.iconflux.Whosebug">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".InitialActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.accountkit.ApplicationName" android:value="@string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
<meta-data android:name="com.facebook.accountkit.ClientToken" android:value="@string/account_kit_client_token" />
<activity
android:name="com.facebook.accountkit.ui.AccountKitActivity"
android:theme="@style/AppLoginTheme"
tools:replace="android:theme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/ak_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:theme="@style/AppTheme"
tools:replace="android:theme"></activity>
</application>
</manifest>
For Style:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#4E86FF</item>
<item name="colorPrimaryDark">#3e6bcc</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppLoginTheme" parent="Theme.AccountKit" >
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
当我尝试在 phone 验证
之后准确获取访问令牌时抛出错误phoneLogin() this method load the UI and all the process goes perfect but when i try
`if (loginResult.getAccessToken() != null) {
Log.e("token", loginResult.getAccessToken().toString());
toastMessage = "Success:" + loginResult.getAccessToken().getAccountId();
}
` 下面提到了它抛出错误的这段代码
错误:400: An internal consistency error has occurred: 406: No access token: cannot retrieve account
代码
public void phoneLogin() {
final Intent intent = new Intent(LoginActivity.this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(
LoginType.PHONE,
AccountKitActivity.ResponseType.CODE); // or .ResponseType.TOKEN
UIManager uiManager = new SkinManager(SkinManager.Skin.CLASSIC, Color.GRAY, R.drawable.bubble_background, SkinManager.Tint.BLACK, 5);
configurationBuilder.setUIManager(uiManager);
// ... perform additional configuration ...
intent.putExtra(
AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
configurationBuilder.build());
startActivityForResult(intent, APP_REQUEST_CODE);
}
@Override
protected void onActivityResult(
final int requestCode,
final int resultCode,
final Intent data) {
super.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();
// showErrorActivity(loginResult.getError());
Log.e("error", loginResult.getError().toString());
} else if (loginResult.wasCancelled()) {
toastMessage = "Login Cancelled";
} else {
if (loginResult.getAccessToken() != null) {
Log.e("token", loginResult.getAccessToken().toString());
toastMessage = "Success:" + loginResult.getAccessToken().getAccountId();
} else {
toastMessage = String.format(
"Success:%s...",
loginResult.getAuthorizationCode().substring(0, 10));
}
// 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...
// goToMyLoggedInActivity();
Log.d("success", toastMessage);
Toast.makeText(this, "success", Toast.LENGTH_LONG).show();
try {
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(Account account) {
String accountKitId = account.getId();
// Get phone number
PhoneNumber phoneNumber = account.getPhoneNumber();
String phoneNumberString = phoneNumber.toString();
SessionManager sessionManager = new SessionManager(getApplicationContext());
sessionManager.setPhone(phoneNumberString);
startActivity(new Intent(LoginActivity.this, MobileVerification.class));
finish();
}
@Override
public void onError(AccountKitError accountKitError) {
}
});
} catch (Exception e) {
Log.d("catch", e.toString());
}
}
// Surface the result to your user in an appropriate way.
}
public void goToLogin(boolean isSMSLogin) {
LoginType loginType = isSMSLogin ? LoginType.PHONE : LoginType.EMAIL;
final Intent intent = new Intent(this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(
loginType,
AccountKitActivity.ResponseType.TOKEN);
UIManager uiManager = new SkinManager(
SkinManager.Skin.CONTEMPORARY,
getResources().getColor(R.color.colorBackground),
R.drawable.bg,
SkinManager.Tint.BLACK,
0.10);
configurationBuilder.setUIManager(uiManager);
intent.putExtra(
AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
configurationBuilder.build());
this.startActivityForResult(intent, APP_REQUEST_CODE);
}
public void smsLogin(View v){
goToLogin(true);
}
public void emailLogin(View v){
goToLogin(false);
}
private void goToMyLoggedInActivity(){
final Intent intent = new Intent(this, SecondActivity.class);
this.startActivity(intent);
}
private void logAssert(String error) {
Log.println(Log.ASSERT, "AccountKit", error);
}
}
只是改变AccountKitActivity.ResponseType.CODE);至 AccountKitActivity.ResponseType.TOKEN);
您必须先登录才能获得访问令牌。
public void phoneLogin(final View view) {
final Intent intent = new Intent(getActivity(), 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);
}
https://developers.facebook.com/docs/accountkit/android#smslogin
第一次你没有访问令牌,这意味着你重定向到移动验证 Screen.Class 并在获得访问令牌后你重定向到 HomeActivity.class 并在共享首选项中存储令牌在终止应用程序时曾经打开应用程序然后重定向到 LoginActivity.class
if (sessionManager.isLoggedIn() && accessToken != null) {
startActivity(new Intent(SplashActivity.this,LoginActivity.class ));
} else {
startActivity(new Intent(SplashActivity.this,Mobile Verfication.class ));
}
你已经把一切都做得很完美了只是改变AccountKitActivity.ResponseType.CODE); to AccountKitActivity.ResponseType.TOKEN);
i have to make demo for You and i successfully Logined with Facebbok accountKit(here not Applying With Permisson):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:backgroundTint="#FFFFFF"
android:background="#FFFFFF">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:backgroundTint="#FFFFFF">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_vertical|center_horizontal"
android:layout_weight=".25"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login with AccountKit"
android:id="@+id/textView6"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:gravity="top|center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="This example shows you how to implement Facebook AccountKit in Android using Java."
android:id="@+id/textView7"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".07"
android:gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Login with Email"
android:id="@+id/button"
android:onClick="emailLogin"
android:backgroundTint="#4E86FF"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".07"
android:gravity="center_horizontal"
android:layout_marginBottom="150dp">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Login with Phone"
android:id="@+id/button2"
android:onClick="smsLogin"
android:backgroundTint="#4E86FF"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
InitialActivity.java:
public class InitialActivity extends AppCompatActivity {
public static int APP_REQUEST_CODE = 99;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AccountKit.initialize(getApplicationContext());
setContentView(R.layout.activity_initial);
AccessToken accessToken = AccountKit.getCurrentAccessToken();
Log.d("accesssToken:----",""+accessToken);
if(accessToken != null){
goToMyLoggedInActivity();
}
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == APP_REQUEST_CODE) { // confirm that this response matches your request
AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
String responseMessage;
if (loginResult.getError() != null) {
responseMessage = loginResult.getError().getErrorType().getMessage();
logAssert(loginResult.getError() + " - " + responseMessage);
} else if (loginResult.wasCancelled()) {
responseMessage = "Login Cancelled";
logAssert(responseMessage);
} else {
if (loginResult.getAccessToken() != null) {
Log.d("Token:-",""+loginResult.getAccessToken());
responseMessage = "Success: " + loginResult.getAccessToken().getAccountId();
logAssert(responseMessage);
} else {
responseMessage = String.format(
"Success:%s...",
loginResult.getAuthorizationCode().substring(0,10));
logAssert(responseMessage);
}
// 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...
goToMyLoggedInActivity();
}
}
}
public void goToLogin(boolean isSMSLogin) {
LoginType loginType = isSMSLogin ? LoginType.PHONE : LoginType.EMAIL;
final Intent intent = new Intent(this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(
loginType,
AccountKitActivity.ResponseType.TOKEN);
UIManager uiManager = new SkinManager(
SkinManager.Skin.CONTEMPORARY,
getResources().getColor(R.color.colorBackground),
R.drawable.bg,
SkinManager.Tint.BLACK,
0.10);
configurationBuilder.setUIManager(uiManager);
intent.putExtra(
AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
configurationBuilder.build());
this.startActivityForResult(intent, APP_REQUEST_CODE);
}
public void smsLogin(View v){
goToLogin(true);
}
public void emailLogin(View v){
goToLogin(false);
}
private void goToMyLoggedInActivity(){
final Intent intent = new Intent(this, SecondActivity.class);
this.startActivity(intent);
}
private void logAssert(String error) {
Log.println(Log.ASSERT, "AccountKit", error);
}
}
Second Activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_second" />
</android.support.design.widget.CoordinatorLayout>
SecondActivity.java:
public class SecondActivity extends AppCompatActivity {
TextView txtAccountKitID, txtUserLoginMode, txtUserLoginData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
txtAccountKitID = (TextView) findViewById(R.id.txtAccountKitID);
txtUserLoginMode = (TextView) findViewById(R.id.txtUserLoginMode);
txtUserLoginData = (TextView) findViewById(R.id.txtUserLoginData);
this.setUserInformation();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public void setUserInformation(){
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(final Account account) {
// Get Account Kit ID
String accountKitId = account.getId();
logAssert("ID: " + accountKitId);
boolean SMSLoginMode = false;
// Get phone number
PhoneNumber phoneNumber = account.getPhoneNumber();
String phoneNumberString = "";
if (phoneNumber != null) {
phoneNumberString = phoneNumber.toString();
logAssert("Phone: " + phoneNumberString);
SMSLoginMode = true;
}
// Get email
String email = account.getEmail();
logAssert("Email: " + email);
txtAccountKitID.setText(accountKitId);
txtUserLoginMode.setText(SMSLoginMode ? "Phone:" : "Email:");
if (SMSLoginMode) {
txtUserLoginData.setText(phoneNumberString);
} else {
txtUserLoginData.setText(email);
}
}
@Override
public void onError(final AccountKitError error) {
logAssert("Error: " + error.toString());
}
});
}
public void LogOut(View v){
AccountKit.logOut();
Intent initialActivity = new Intent(this, InitialActivity.class);
this.startActivity(initialActivity);
this.finish();
}
private void logAssert(String error) {
Log.println(Log.ASSERT, "AccountKit", error);
}
}
Android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.iconflux.Whosebug">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".InitialActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.accountkit.ApplicationName" android:value="@string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
<meta-data android:name="com.facebook.accountkit.ClientToken" android:value="@string/account_kit_client_token" />
<activity
android:name="com.facebook.accountkit.ui.AccountKitActivity"
android:theme="@style/AppLoginTheme"
tools:replace="android:theme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/ak_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:theme="@style/AppTheme"
tools:replace="android:theme"></activity>
</application>
</manifest>
For Style:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#4E86FF</item>
<item name="colorPrimaryDark">#3e6bcc</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppLoginTheme" parent="Theme.AccountKit" >
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />