可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
hello all in one of my app I need to get data of fb... I am doing that..
I have created app ID it log in successfully but after log out i Log In then it gives me
What is wrong I am doing? Please suggest I am using Facebook sdk... I have installed Facebook in my phone... this running good in emulator that does not have inbuilt Facebook application installed
this is my code
if (FB_APP_ID == null) {
Builder alertBuilder = new Builder(this);
alertBuilder.setTitle(\"Warning\");
alertBuilder.setMessage(\"A Facebook Applicaton ID must be \" +
\"specified before running this example: see App.java\");
alertBuilder.create().show();
}
// Initialize the dispatcher
Dispatcher dispatcher = new Dispatcher(this);
dispatcher.addHandler(\"login\", LoginHandler.class);
dispatcher.addHandler(\"stream\", StreamHandler.class);
dispatcher.addHandler(\"logout\", LogoutHandler.class);
// If a session already exists, render the stream page
// immediately. Otherwise, render the login page.
Session session = Session.restore(this);
if (session != null) {
dispatcher.runHandler(\"stream\");
} else {
dispatcher.runHandler(\"login\");
}
回答1:
The generate hash key is wrong. You may get the hash key using two steps. One is through command prompt. Another one is through coding. Hash key through command prompt working on first time only. I don\'t know the reason. I have also got the same problem. So i tried it through programatically.
Follow this steps:
Paste the following code in oncreate()
.
try {
PackageInfo info = getPackageManager().getPackageInfo(
\"com.example.packagename\",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance(\"SHA\");
md.update(signature.toByteArray());
Log.d(\"KeyHash:\", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
Modify \"com.example.packagename\" with your package name in the above coding without fail(You may found your package name in Android Manifest file).
Run your application. Go to the activity where you pasted the above code. In the logcat search for \"KeyHash\". You may found a key hash. Copy the key hash and go to Facebook application dashboard page. Go to settings and enter the details like in the bellow image.
Once you finished the above step. Relaunch the app again you may now log into the facebook.
For more details about key hash check the link
If you add a wrong information in the settings page means it will give some error. so use the correct information there. And also if public(other than you) need to use your application means you need to enable the permission(change \"yes\" in the \"Status & Review\" next to setting)
.
回答2:
If you are facing this problem then put this key into your developer.facebook.com
Then make sure your app is live on
developer.facebook.com
This green circle is indicating the app is live
If it is not then follow this two steps for make your app live
Step 1 Go to your application -> setting => and add Contact Email and apply save Changes
Setp 2 Then goto App Review option and make sure this toggle is Yes i added a screen shot
Note: If you want to copy hashkey check the BlueServiceQueue in Logcat.
回答3:
If you are using Google Play App Signing:
Open App signing section in Google Play Console, and get SHA1 of app signing certificate, than convert it to base64, for example with this tool: http://tomeko.net/online_tools/hex_to_base64.php?lang=en
回答4:
I got the same problem.I was sure that it was due to very small fault and yes it was!!!!
I found the solution.
When generating debug hash key in my computer, I entered the password of my system.But the password should be the following -
Enter keystore password: \"android\"
This was the only problem in my case.
----- For generating Debug key hash, use this command -
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Enter keystore password: \'android\'
----- To Generate Release key hash, use this command -
keytool -exportcert -alias \"alias of keystore\" -keystore \"Your path to the keystore when signing app\" | openssl sha1 -binary | openssl base64
Provide your keystore password after executing this command.
回答5:
I experienced the same problem. I made a short research on the possible reasons for this strange behavior and I found the following:
During the first execution of a new Facebook app, it will allow connection/login even if you don\'t specify any key hashes.
For me, the tutorial which Facebook provided didn\'t generate the correct key hash, because it was giving the wrong configuration. When executing:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\\.android\\debug.keystore | openssl sha1 -binary | openssl
base64
make sure you check all properties - the HOMEPATH
, the existence of the keystore, etc. Maybe you also have to provide password.
What generated the proper configuration was the solution suggested by @Mahendran.
Also, if you see the error originally posted (http://i.stack.imgur.com/58q3v.png), most probably the key hash you see on the screen is your real one. If nothing else works, try inputting it in Facebook.
I got all those results with: Windows 7 64-bit edition, Android Studio 1.2.2, JDK 7.
回答6:
According Facebook Login for Android, you must provide the Key Hash value. In order to obtain it, you will need the key used to sign your application.
keytool \\
-exportcert \\
-alias YourKeyAlias \\
-storepass YourStoreKeyPassword \\
-keystore PathToYourKeyStoreFile | openssl sha1 -binary | openssl base64
回答7:
I tried all of the above and nothing helped my case with my clients!
Than my client remembered he had the Facebook App installed on his device.
After he removed it the login worked perfectly.
The hashkey has been changed and I\'ve replaced the old hash keys at Facebook Developers Console with the key from the error (as suggested above) and it works!
The Facebook App itself might be the issue, so you better figure this out on a device with the Facebook app installed and on a device with the Facebook app not installed and handle both cases..
回答8:
You must create two key hashes one for Debug and one for Release.
For Debug key hash:
On OS X, run:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
On Windows, run:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\\.android\\debug.keystore | openssl sha1 -binary | openssl
base64
Debug key hashes source
For Release key hash:
On OS X, run: ( Replace what between <> with your values )
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
On Windows, use: ( Replace what between <> with your values )
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
Release key hashes source
回答9:
I was having the same problem. First login, just fine, but then, invalid key hash.
Even though this is not a Unity thread, I found my answer here. So I will leave my answer, just in case someone else (strayed like me) stumbles upon it.
Facebook SDK for Unity gets the wrong key hash. It gets the key from \"C:\\Users\\\"your user\".android\\debug.keystore\" and, in a perfect world, it should get it from the keystore you created in your project. That\'s why it is telling you that the key hash is not registered.
As suggested by Madi, you can follow the steps on this link to find the right key. Just make shure point them to the keystore inside your project, otherwise you won\'t get the right key.
回答10:
paste the following code into your OnCreate Method
try {
PackageInfo info = getPackageManager().getPackageInfo(
\"com.example.packagename\",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance(\"SHA\");
md.update(signature.toByteArray());
Log.d(\"KeyHash:\", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
Just modify the package name.Then go to your Log cat and select Debug search here then you will find the hash key. Now copy this hash key and then go to developer.facebook.app_id site then edit your hash key then press save. Now run your android project again I think issue will be resolved.
回答11:
After a long research, we found a solution.
We had set permissions as:
loginButton.setReadPermissions(public_profile email);
This worked for the first time, but when we re-logged in to FB, it gave the Invalid Hash Error.
The simple solution was to change the above line to:
loginButton.setReadPermissions(Arrays.asList(
\"public_profile\", \"email\"));
And it worked like a bliss!
Hopefully this helps someone.
Facebook should return the correct exception instead of the misleading invalid hash key error.
回答12:
This code will give you your hash for facebook but you have to follow these steps in order to get the release condidate hash .
1. copy and paste this code in your mainactivity
try {
PackageInfo info = getPackageManager().getPackageInfo(
\"com.example.packagename\",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance(\"SHA\");
md.update(signature.toByteArray());
Log.d(\"KeyHash:\", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
- generate signed apk.
- connect your phone to laptop and make sure it stays connected .
install and run the apk in your phone by manually moving the release apk to your phone.
now look at android logcat (use filter KeyHash: ) you should see your release hash key for facebook . simply copy and paste it in your https://developers.facebook.com/apps it\'s under settings.
now you can test the app it should work perfectly well.
good luck.
回答13:
This may help some one with same problem
- Generate key hash using below code
keytool -exportcert -alias <your_keystore> alias -keystore <your_keystore_file> | openssl sha1 -binary | openssl base64
how to use keytool
2.Paste it in required field in facebook developer
3.In android studio File->Project Structure
add signing parameters
4.Select flavors
select signing config we created
5.select build type
6.select build varient and build it
回答14:
I had the same problem when I was debugging my app. I\'ve rewrited the hash that you have crossed out in the attached image (the one that Facebook says is invalid) and added it in Facebook\'s developers console to key hashes. Just be careful on typos.
This solution is more like easy work-around than a proper solution.
回答15:
After so much trials i stumbled on a solution to this. I generated and added both debug and release keys to Facebook developer console and still gets the error.
The only solution that worked for me was is to uninstall the OpenSSL program from google and download from http://slproweb.com/products/Win32OpenSSL.html
It really works like magic
回答16:
What facebook used is not the default password and alias for debug. You need to change it following and it will work.
/usr/lib/jvm/jdk1.8.0_66/bin/keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
If you have not change anything with default password it should be android.
You can also configure it in the build.gradle file. But the same alias password should be used for generating hash.
android{
signingConfigs {
release {
storeFile file(\"~/.android/debug.keystore\")
storePassword \"android\"
keyAlias \"androiddebugkey\"
keyPassword \"android\"
}
}
}
回答17:
If you are typing the keyhash manually (for example from Mobile to the Facebook Dashboard), make sure to differentiate between small L and capital I.
回答18:
Use below code in onCreate() method of your activity
try {
PackageInfo info = getPackageManager().getPackageInfo(
\"your application package name\",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance(\"SHA\");
md.update(signature.toByteArray());
Log.d(\"KeyHash:\", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
Run this code, this will generate Hash key. copy this KeyHash in Facebook application setting --> Save changes. then Log in your application. this will work perfectly in future too.
回答19:
Guys here is a lot of right answers. Just one thing. Paste received hash into Application -> Settings -> Main not via fast start tutorial.