简体   繁体   中英

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

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})

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?

最新版本的sdk修复了这个问题,可在此处下载: https//developers.facebook.com/docs/unity/downloads/

I resolved by try download new openssl from this

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

and change new hash key.

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.

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...

那么发布密钥库,我正在使用Unity签署我的应用程序,我从Unity创建的密钥库中获取了keyhash,但是同样的错误,登录显示,但是is_logged_in:false

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 :)

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.

@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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM