简体   繁体   中英

Facebook login not working with Parse Android SDK

I'v tried a lot of solutions to implement Facebook login based on the Parse SDK without success. It seems like I'm missing something.

Generating Facebook hash

I tried to generate the hash with this command (and many others) and password = android:

keytool -exportcert -alias androiddebugkey -keystore C:\\Users\\Ido\\.android\\debug.keystore | openssl sha1 -binary | openssl base64

But it didn't work for me, every time I tried to login I got an error that the hash key is not authorized. Putting this code in the Appliction OnCreate made the work for me (I didn't get the error anymore):

try {
        PackageInfo info =     getPackageManager().getPackageInfo("com.idob.soccertimer",     PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String sign= Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.e("MY KEY HASH:", sign);
            Toast.makeText(getApplicationContext(), sign, Toast.LENGTH_LONG).show();
        }
    } catch (PackageManager.NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }

Application implementation

I made the adjustments for the Facebook and Parse:

Initialize in the onCreate of the Application:

ParseFacebookUtils.initialize(getString(R.string.facebook_app_id));

Overriding the onActivityResult method in my loginFragment:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
}

Add meta tag:

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

I use this code to login:

ParseFacebookUtils.logIn(getActivity(), new LogInCallback() {
                @Override
                public void done(ParseUser user, ParseException err) {
                    if (user != null) {
                        Log.e("MyApp", err.getMessage());
                    }
                    if (user == null) {
                        Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
                    } else if (user.isNew()) {
                        Log.d("MyApp", "User signed up and logged in through Facebook!");
                    } else {
                        Log.d("MyApp", "User logged in through Facebook!");
                    }
                }
            });

My problem is that the LogInCallback don't call, when I try to login twice - one LogInCallback is returned with user = null and err = null The OnActivityResult is not called at all.

This path looks wrong to me :

C:\Users\Ido. android\debug.keystore

I'm a linux user and can't be 100% sure on windows paths, but I'm pretty sure it should be located :

C:\Documents and Settings\[User Name]\.android\debug.keystore

or

C:\Users\[User Name]\.android\debug.keystore

片段的onActivityResults不会自动调用,应该由活动的onActivityResult调用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM