Facebook SDK and Keyhash
After an app on the Facebook developer portal is created, before we can use Facebook API on behalf of our created Facebook application, we need to make sure that all settings are correct.
The first one is very easy. The app id should match.
Get your app id from Facebook Developer portal:
And specify it under the Facebook Editor Setting.
Facebook -> Edit Settings:
Now Under Application Android platform settings we need to specify Google Play Package Name, nad Key Heshes.
The Google Play Package Name is your app bundle id which should be specified under the Player Settings inside Unity Editor:
Now the hardest part which triggers lot's of questions. The Key Hashes which you need to specify in the app settings.
So, what is the Key Hash. The Key Hash is your app unique signature. We need to specify it to make sure that only our official application can use Facebook API on behalf of our created Facebook application. When you try to make a FB API call, it will be signed with your app Key Hash by FB SDK. The Key Hash will be retrieved in runtime from your Application. Since the app Key Hash is your unique app signature, it stores in the key store which you use to sign your app.
So, for example, If I am not signing my APK with specific keystone which means that I am going to use еру default debug key store. The Debug key store is located somewhere on your PC or Mac after you have installed Android SDK. You can read this thread to find out more. To sing your app with the debug Keystore, your android build setting should look like this:
The Key Hash of this Keystore can be detected by Unity Facebook SDK, and you can actually get it very easily from SDK editor settings. Just go to the Facebook -> Edit Settings:
But you are signing your app with your own key store as shown on screenshot below
You can get your app Key Hash using the console
keytool -exportcert -alias <alias_name> -keystore <path_to_keystore> | openssl sha1 -binary | openssl base64
Do not afraid if that seems hard for you. There is one more way.
1) Build your app as it is.
2) Open Logcat log
3) Try to make FB API call, and monitor your device log output, and you will see Key hash FB SKD is trying to use for API request signature. If you have not specified your correct Key Hash in FB app settings, you will see that the picture is similar to this:
And device output similar to this:
12-26 12:25:48.862: W/fb4a(:<default>):BlueServiceQueue(3537): Exception during service 12-26 12:25:48.862: W/fb4a(:<default>):BlueServiceQueue(3537): com.facebook.http.protocol.ApiException: [code] 404 [message]: Key hash 4rlCn2qAR6IXFopNf3u3lah0ehs does not match any stored key hashes. [extra]: null
4) Simply add this Key Hash to your FB app settings, and you are good to go.