Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
999 views
in Technique[技术] by (71.8m points)

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

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.

Because the Android Key Hash is empty ( even it shouldn't be ) I used the methods posted by others to create one with openssl. I created it and copied over to facebook as required.

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? 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. 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. Can anybody help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Version 4.3.6 of the sdk should fix this problem. 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.


Note - it's still broken (5/2014) IF you use a Mac. Just follow the "Rafael solution", discover your hash properly from public void OnLoginComplete(string message). Cheers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...