Facebook SDK for Unity on Android - Trouble about callback from FB.Login

走远了吗. 提交于 2019-12-11 07:49:53

问题


I'm having some problem about login in facebook-unity-sdk on android device. When I login and get callback, them return this

FBResult.Text

{"is_logged_in":false,"user_id":"","access_token":""}

FBResult.Error

null

and FB.IsLoggedIn is null everytime after login completed

I'm using last version of Facebook SDK (4.2.1) and Unity 4.2

On Debug Log

Send to Unity OnLoginCompleted({"cancelled":true})

回答1:


These problems are usually caused by two things:

Keyhash setup

You can set your logcat to filter messages with log tag "fb4a" and you will see underlying Facebook Android SDK throwing exception saying your keyhash doesn't match any stored keyhashes.

You can just copy that keyhash and add it to Facebook developer dashboard.

Other plugins

We have new v5.0.2 beta version of the SDK which should play nice with other plugins.

Check Brian's answer in this thread How to work with Facebook SDK for Unity and Vuforia for Android?




回答2:


The latest version of the sdk fixes this and is available for download here: https://developers.facebook.com/docs/unity/downloads/




回答3:


I resolved by try download new openssl from this

http://gnuwin32.sourceforge.net/packages/openssl.htm

and change new hash key.




回答4:


have the same problem, I export the test scene as is and does not work with facebook app installed.

Im using sdk v4.2.4.




回答5:


Try upgrading your openSSL and regenerating the keyhash, I was stuck on this issue for a few days trying over and over again everything that came to my mind... Until I read someone did that so I tried and magic ! All the test projects I tried to make the FB SDK work with are doing just fine ;)

I used the one from this page if anyone wonders.

Such a waste of time that would have been avoided if the error field did tell what was wrong...




回答6:


What about release keystore, I am signing my app with Unity , and I get the keyhash from the keystore that Unity created, but same error, login shows up , but is_logged_in :false




回答7:


My problem has resolved now. This problem is about Multi-Plugin on project. Now (I think), Facebook SDK can't use with other plugin that want main activity for them on android. Export android project and recheck AndroidManifest.xml and maintain them for right things, It should have FBUnityActivity for singletask that many plugin override them so facebook can't get session on game launch. Hope for next version this SDK can use with another plugin. Thank you everyone for advise :)




回答8:


The Facebook Unity plugin for Android doesn't play nice with other plugins as it overrides the MainActivity, so unless you launch it first (from the AndroidManifest.xml) it won't return any data (login info, friend lists) back to Unity and to your game.

Of course, most other plugins now don't work.

I have my own plugin (pure java compiled in eclipse) that handles Saving, IAP, notifications, etc and i launch that plugin first - to make the Facebook plugin work you have to add a small bit of Facebook "Session" code to onActivityResult in your own Main Activity class:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    // Pass on the activity result to the helper for handling
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
        // not handled, so handle it ourselves (here's where you'd
        // perform any handling of activity results not related to in-app
        // billing...

        // Facebook callback

        if (Session.getActiveSession() != null) {
            Session.getActiveSession().onActivityResult(this, requestCode,
                    resultCode, data);
        }

        super.onActivityResult(requestCode, resultCode, data);
    } else {
    }
}

You need the FacebookSDK.jar for this to compile, and i was as surprised as anyone when it worked; but this won't help if you are using other 3rd party plugins and don't have access to their source.

Writing Unity plugins for Android is a nightmare.




回答9:


@user2830062 re-checking your keyhash. When you was get correct keyhash, with each computer you need get new keyhash and add to dev facebook page (list keyhash)



来源:https://stackoverflow.com/questions/18959004/facebook-sdk-for-unity-on-android-trouble-about-callback-from-fb-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!