Facebook login fails with FB app installed

2019-06-09 20:37发布

问题:

Using Unity 4.3 and Facebook SDK 5.0.3 / 5.0.4 beta I seem to be unable to log in to Facebook on Android using FB.Login("publish_actions", LoginCallback). My game shows the "Game would like to post to your friends on your behalf"-message. After tapping OK, I get an ajax-spinner for about 2-3 seconds after which I'm brought back to my game without being able to post a FB.Feed.

The message I'm getting is:

V/FBUnitySDK( 8892): sending to Unity OnLoginComplete({"cancelled":true,"key_hash":"XXXXXXXXXXXXXXXXXXX"})

As soon as I remove the Facebook app, everything seems to work fine and I'm getting a popup that asks for my publish_actions permissions.

I also looked into the key hash problem and was able to find the correct key_hash by getting FB.Android.KeyHash.

Is there a way around this?

回答1:

if there is the default Facebook App is installed in your phone or if you are trying to upload your app on Google Play, then you need a different KeyHash. because, when u developed your FB app you have registered your FB app with a key hash which is created by using the default debug.keystore.

so, now u need a different KeyStore to generate the different KeyHash. u need a signed KeyStore, which u can get by the help of this tutorial , after generating new keystore, generate a key hash and register your FB App with this new key hash. this should work. for generating new KeyHash u can follow this link.



回答2:

Okay, I finally figured it out.

On Mac, in Terminal, enter the following:

keytool -list -keystore pathtokeystorefile.keystore | openssl sha1 -binary | openssl base64

You'll be prompted to enter the password. Do so and you will get your valid KeyHash.