简体   繁体   English

Facebook UNITY SDK登录问题

[英]Facebook UNITY SDK login issue

I just installed the new version of Unity 4.3 and the new facebook sdk and I can't get it working. 我刚刚安装了新版本的Unity 4.3和新的facebook sdk,但我无法使用它。

I created the app on facebook, copied over the app id to the unity facebook settings as required and copied the Package Name and Class name back to facebook. 我在facebook上创建了应用程序,根据需要将app id复制到unity facebook设置,并将Package Name和Class名称复制回facebook。

Because the Android Key Hash is empty ( even it shouldn't be ) I used the methods posted by others to create one with openssl. 因为Android Key Hash是空的(即使它不应该),我使用其他人发布的方法来创建一个openssl。 I created it and copied over to facebook as required. 我根据需要创建并复制到Facebook。

After this I created a small script to be able to login. 在此之后我创建了一个小脚本以便能够登录。

// Use this for initialization
void Start () {
    enabled = false;                  
    FB.Init(SetInit, OnHideUnity);  
}

// Update is called once per frame
void Update () {

}

private void SetInit()                                                                       
{                                                                                            
    FbDebug.Log("SetInit");                                                                  
    enabled = true; // "enabled" is a property inherited from MonoBehaviour                  
    if (FB.IsLoggedIn)                                                                       
    {                                                                                        
        FbDebug.Log("Already logged in");                                                    
        OnLoggedIn();                                                                        
    }                                                                                        
}                                                                                            

private void OnHideUnity(bool isGameShown)                                                   
{                                                                                            
    FbDebug.Log("OnHideUnity");                                                              
    if (!isGameShown)                                                                        
    {                                                                                        
        // pause the game - we will need to hide                                             
        Time.timeScale = 0;                                                                  
    }                                                                                        
    else                                                                                     
    {                                                                                        
        // start the game back up - we're getting focus again                                
        Time.timeScale = 1;                                                                  
    }                                                                                        
}    

void OnGUI(){
    if (!FB.IsLoggedIn)                                                                                              
    {                                                                                                                         
        if (GUI.Button(new Rect(179 , 11, 287, 160), "Login to Facebook"))                                      
        {                                                                                                            
            FB.Login("email", LoginCallback);                                                        
        }                                                                                                            
    }    
}

void LoginCallback(FBResult result)                                                        
{                                                                                          
    FbDebug.Log("LoginCallback");                                                          
    Debug.Log("LoginCallback");
    if (FB.IsLoggedIn)                                                                     
    {                                                                                      
        OnLoggedIn();                                                                      
    }                                                                                      
}                                                                                          

void OnLoggedIn()                                                                          
{                                                                                          
    FbDebug.Log("Logged in. ID: " + FB.UserId);                                            
} 

Now when I click on the login button a Facebook window appears requesting permission, after I press ok, it returns, but I'm still not logged in... Can anybody help why is this? 现在,当我点击登录按钮时,会出现一个请求权限的Facebook窗口,在我按下确定后,它会返回,但我还没有登录...有人可以帮忙吗? Another strange thing I observed that the LoginCallback gets called as soon as I click on the login button, even though I would think it should only when I gave permission. 我发现另一个奇怪的事情是,一旦我点击登录按钮就会调用LoginCallback,即使我认为只有在我允许的情况下才应该这样做。 Anyway when I give permission it returns to my app and nothing happens. 无论如何,当我给予许可它返回我的应用程序,没有任何反应。 I can click on the login button again and same thing happens, login callback called, it asks for permisions, I give the permision and returns back, nothing happened. 我可以再次单击登录按钮,同样的事情发生,登录回调呼叫,它要求permisions,我给permision并返回,没有任何反应。 Can anybody help? 有人可以帮忙吗?

Version 4.3.6 of the sdk should fix this problem. sdk的4.3.6版应该可以解决这个问题。 It's available here: https://developers.facebook.com/ We are still waiting for it to be approved on the asset store, so the only place to get it right now is from Facebook's site. 它可以在这里找到: https//developers.facebook.com/我们还在等待它在资产商店获得批准,所以现在唯一能够获得它的地方是来自Facebook的网站。


Note - it's still broken (5/2014) IF you use a Mac. 注意 - 如果您使用的是Mac,它仍然会损坏(2014年5月)。 Just follow the "Rafael solution", discover your hash properly from public void OnLoginComplete(string message). 只需按照“Rafael解决方案”,从public void OnLoginComplete(字符串消息)中正确发现您的哈希。 Cheers 干杯

So after being frustrated for a few days with having to trace out the key to my phone, I decided to look into what it was doing. 因此,在不得不追踪我的手机钥匙几天后感到沮丧,我决定调查它在做什么。

After some research it turned out that when you published to an android device, facebook would use the keystore that was defined in your publish settings, not your .android/debug.keystore file. 经过一些研究后发现,当你发布到Android设备时,facebook会使用你的发布设置中定义的密钥库,而不是你的.android / debug.keystore文件。 So I went in and changed the sdk to make it work the proper way. 所以我进去改变了sdk以使其以正确的方式工作。 Essentially I changed the SDK to look at the ProjectSettings instead of the debug directory for grabbing the key hash. 基本上我改变了SDK来查看ProjectSettings而不是调试目录来获取密钥哈希。 In the FacebookAndroidUtils.cs I added the following. 在FacebookAndroidUtils.cs中,我添加了以下内容。

// Using the user defined keystore values instead of the debug one.
degbugKeyHash = GetKeyHash( PlayerSettings.Android.keyaliasName, PlayerSettings.Android.keystoreName, PlayerSettings.Android.keyaliasPass, PlayerSettings.Android.keystorePass );

I created a small repo that provides the fix as well as some gui changes to make it more easy to update the key hash. 我创建了一个小型repo,提供修复以及一些gui更改,以便更容易更新密钥哈希。

Github Facebook Unity SDK 6.1 Fix Github Facebook Unity SDK 6.1修复

Update - Fixed a bug with OS X related to escaping spaces on the string path 更新 - 修复了OS X与字符串路径上的空间转义相关的错误

Hope this helps! 希望这可以帮助!

Take the "email" permission out of the login function and try it. 从登录功能中获取“电子邮件”权限并尝试使用。 Oops I thought I seen the "publish_actions" permission in there too. 哎呀我以为我也看到了“publish_actions”的许可。

Make sure the loginactivity in the manifest is in portrait. 确保清单中的loginactivity是纵向的。

Instead of implementing everything yourself, try using the free and open source SOOMLA Profile plugin for all of your social network needs: https://github.com/soomla/unity3d-profile 不要自己实现所有内容,请尝试使用免费和开源的SOOMLA Profile插件来满足您的所有社交网络需求: https//github.com/soomla/unity3d-profile

Also available on the asset store for download: https://www.assetstore.unity3d.com/en/#!/content/24601 也可在资产商店下载: https//www.assetstore.unity3d.com/en/#!/ content / 24601

It covers Facebook, Twitter and Google+ and has a unified API for logging in, posting statues, uploading images and getting friends lists. 它涵盖Facebook,Twitter和Google+,并具有统一的API,用于登录,发布雕像,上传图像和获取朋友列表。 For proper disclosure, I'm one of the founders. 为了正确披露,我是其中一位创始人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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