Mushahid Khatri
Mushahid Khatri

Reputation: 728

Facebook Account Kit OnActivityResult not getting proper data

I am using facebook account kit for verification of the mobile number. Some how I in few cases I am getting System Issue occurred. Please try again later.

Even I am not getting anything onActivityResult as pressing back again putting me to enter mobile number screen that is from SDK itself.

Below is the code of ActivityResult

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);



        if (requestCode == 99) { // confirm that this response matches your request
            AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
            String toastMessage;
            if (loginResult.getError() != null) {
                AccountKitError error = loginResult.getError();
                try{
                    int code  = error.getDetailErrorCode();
                    String message = error.getUserFacingMessage();
                    AccountKitError.Type type = error.getErrorType();


                    String str_error = "Code : "+code+"\ndescription : "+message+"\ntype : "+type.name()
                            +"\ntype_message : "+type.getMessage()+"\ntype_code : "+type.getCode();
                    showAlert(str_error);
                }catch (Exception e){
                }
                Toast.makeText(getApplicationContext(),"Login Error",Toast.LENGTH_SHORT).show();

            } else if (loginResult.wasCancelled()) {
                Toast.makeText(getApplicationContext(),"Login Canceled",Toast.LENGTH_SHORT).show();

            } else {

                Toast.makeText(getApplicationContext(),"Logged IN",Toast.LENGTH_SHORT).show();

            }

        }

    }

But it always go to login canceled. As per below link https://developers.facebook.com/docs/reference/android/4.11/interface/AccountKitLoginResult/ the AccountKitLoginResult is no longer available but still in overview suggesting to use same.

Any one has the same issue?

Upvotes: 1

Views: 1025

Answers (1)

Pouya Larjani
Pouya Larjani

Reputation: 408

AccountKitLoginResult is actually available and it's the right way of getting the data. I think you were just looking at the older documentation. Here is the current one: https://developers.facebook.com/docs/reference/androidsdk/current/AccountKit/com/facebook/accountkit/accountkitloginresult.html/

Does your app go directly from entering the phone number screen to error screen without giving you the option to enter your verification key? If so, then the onActivityResult shouldn't get called since there was a system error. Here's a few suggestion for where the error might be coming from:

  1. Check that in your AndroidManifest.xml, you have the the meta data set for all 3 of: com.facebook.accountkit.ApplicationName , com.facebook.sdk.ApplicationId , com.facebook.accountkit.ClientToken
  2. Make sure the values for those metadata are actually @string/... keys and NOT just the direct value. I made this mistake on my first accountkit app too and took me a few tries to realise this.
  3. The other big mistake I made in my app was that I had the App ID and App Name switched around and it just told me "system error occurred" so it took me a while to realise that I was sending wrong values for those
  4. Also, just check if you have AccountKit installed under the "products" tab in your app's settings and the right client token is passed on your manifest.

If you still can't fix it, maybe you could post the part of your AndroidManifest and your onLogin method (where you set up AccountKitConfiguration) to give more context

Upvotes: 1

Related Questions