How to create a Facebook key hash?

2020-02-08 10:01发布

In the Facebook android tutorial we are told to use following code to create a key hash:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Is this the exact code to use in all situations? For example instead of ~/.android/debug.keystore should it something like C:/folderone/foldertwo/.android/debug.keystore?

As you can see I'm unsure of whether inverted commas are required or not, whether full paths are required or not!

Is anyone able to provide a real world example?

See
https://developers.facebook.com/docs/mobile/android/build/#sso

8条回答
劳资没心,怎么记你
2楼-- · 2020-02-08 10:22

One brute force option is to just go ahead and try to share something from your app. My app then displays a Facebook page with the key it is trying to match. Then you can just copy this key and put it in your Facebook 'Settings' page on your developer Facebook account.

Not ideal, but in a pinch it may be helpful.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-02-08 10:25

When having the error in the log, when trying to login to Facebook, look for something that looks like:

Invalid key hash. The key hash *** does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/565561836797777

where "***" is the key that you need to use.

查看更多
地球回转人心会变
4楼-- · 2020-02-08 10:27

try

try {
PackageInfo info = getPackageManager().getPackageInfo("com.eatapp", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(signature.toByteArray());
    Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

in your main Activity :-) This is the only solution it works for me for Android SDK 3.0

查看更多
看我几分像从前
5楼-- · 2020-02-08 10:35

keytool -exportcert -alias androiddebugkey -keystore "debug.keystore path" | openssl sha1 -binary | openssl base64

if you haven't setup environment variables for open ssl and java sdk than put jdk's bin folder path in place of keytool and your openssl path in place of openssl and not to forget to put double quotes for your path

ex-"C:\Program Files\Java\jdk1.5.0_11\bin" -exportcert -alias androiddebugkey -keystore "C:\Users\amin.android\debug.keystore" | "F:\openssl\binsha1\openssl.exe" -binary | "F:\openssl\binsha1\openssl.exe" base64

查看更多
爷的心禁止访问
6楼-- · 2020-02-08 10:42

In eclipse, window -> preferences -> Android -> build -> default debug keystore, copy the path to replace the ~/.android/debug.keystore

查看更多
萌系小妹纸
7楼-- · 2020-02-08 10:43

I had the same problem, I spend a couple of hours to find a solution, but actually the Facebook SDK provides the solution by itself.

in the DialogListener class I modified the onFacebookError method:

@Override 
public void onFacebookError(FacebookError error) {
   Log.d("myTag",error.getmessage); 
 }

Execute the app (which was sign with the same key i use for the market), and on LogCat will be a message under this tag with the correct key.

We had also created a simple project which does all the work, and returns the correct key on an alert-box and on LogCat. You can find it on our blog.

查看更多
登录 后发表回答