Facebook Unity – Keystore missing

So I just recently noticed that the Facebook team wrote a unity plugin to make your games easily integrate with Facebook! I’m super excited to get Conflicademia connected so off I went.

Apparently, a while ago, I attempted this before and found an old Facebook assembly that I couldn’t get working. It also conflicted with the new library and so step one was to remove that booger. This is not likely something anyone else will have to do.

The next thing was to correct an issue with the imported module. In the Assets/Facebook/Editor/android/FacebookAndroidUtil.cs class, there is a method to return the debug key store path. When imported it looked like the following

private static string DebugKeyStorePath
{
    get
    {
         return (Application.platform == RuntimePlatform.WindowsEditor) ?
            System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" : 
            System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + @"/.android/debug.keystore";
    }
}

Problem is that the HOMEPATH variable doesn’t include the root drive on my machine. I assume it must include the root drive on the devs @ Facebook who worked on it. So I modified it to the following

private static string DebugKeyStorePath
{
    get
    {
        return (Application.platform == RuntimePlatform.WindowsEditor) ?
            System.Environment.GetEnvironmentVariable("HOMEDRIVE") + 
            System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" : 
            System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + @"/.android/debug.keystore";
    }
}

Once that went though, I also went through the steps of creating a keystore and key in Unity through the Player/Platform settings. Facebook wasn’t working, most likely because I actually created this keystore. So I thought it was most likely due to the Key hash that Facebook requests. I used the popular keytool command that I’ve regularly seen on stackoverflow to get the keyhash but that didn’t work. I then enabled development mode and monitored the Android logging output. When I filtered to “Unity” I discovered the following line in the verbose settings

02-16 13:05:24.388: V/FBUnitySDK(22110): sending to Unity OnInitComplete({"key_hash":"[SuperDuperSecretHashKey]\n"})

I want to note that it actually put a line feed at the end of the key, so when I copied and pasted the key into facebook I had to make sure it didn’t include the has key. With that, I did a little bit more experiments and I am connected!

Conflicademia with facebook!
Conflicademia with facebook!

I’d like to get back to my next Topcoding video and this time it’s seriously a challenge! I’m not even at the coding part of it yet either! :p

Leave a Reply