2017-11-20 4 views
0

Ich erstelle ein LOGIN-System mit FACEBOOK SDK 7.4.0 Version und Unity 5.6.3P2. Es erhält erfolgreich die Informationen, die ich benötigte, als ich mich zuerst anmeldete. Ich habe tatsächlich 2 Probleme mit dem FACEBOOK SDK.Facebook SDK-Sitzung (UNITY)

1.) Wenn ich mich abmelde, gehe ich zu meinen Landingmenüs zurück. Jetzt tritt das Problem hier auf, denn wenn ich versuche, mich wieder anzumelden, funktioniert es nicht mehr so ​​weiter. Like This 2.) Wenn ich mich zum ersten Mal anmelde, bekomme ich die gewünschten Informationen, wenn ich meine Anwendung schließe und sie wieder öffne. Ich muss erneut auf den Login-Button klicken, der nicht so sein soll. Es ist wie keine Sitzung im FACEBOOK SDK.

Hier ist mein Code so weit.

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.UI; 
//include for facebook namespace 
using Facebook.Unity; 

public class FBManager : MonoBehaviour { 

public GameObject LoggedIn; 
public GameObject LoggedOut; 
public GameObject ProfilePicture; 
public GameObject username; 

public Text Status; 
//Button for the Google Account 
public GameObject GoogleAccount; /*Just uses this for the setActive of the button */ 
//Button for the Local Account 
public GameObject LocalAccount; /*disable this*/ 
//Button for the playstore 
public GameObject PlayStoreAccount; /*disable this*/ 

void Awake(){ 
    FB.Init (OnSetInit, OnHideUnity); 
} 

void OnSetInit(){ 
    if (FB.IsLoggedIn) { 
     Debug.Log ("FB is Logged in"); 
     Status.text = "FB is Logged In"; 
    } else { 
     Debug.Log ("FB is not Logged in"); 
     Status.text = "FB is not Logged In"; 
    } 
    DealWithFBMenus (FB.IsLoggedIn); 
} 

void OnHideUnity(bool isGameShown){ 
    if (!isGameShown) { 
     Time.timeScale = 0; 
    } else { 
     Time.timeScale = 1; 
    } 
} 

public void FbLogin(){ 
    List<string> permissions = new List<string>(); 

    //ask for public profile 
    permissions.Add("public_profile"); 

    FB.LogInWithReadPermissions (permissions, AuthCallBack); 
} 

public void FbLogout(){ 
    List<string> permission = new List<string>(); 

    FB.LogOut(); 
    //remove public Profile 
    permission.Remove("public_profile"); 
    DealWithFBMenus (FB.IsLoggedIn); 
    Debug.Log ("FB is Logged Out"); 
    Status.text = "FB is Logged Out"; 

} 

void AuthCallBack(IResult result){ 
    if (result.Error != null) { 
     Debug.Log (result.Error); 

    } else { 
     if (FB.IsLoggedIn) { 
      Debug.Log ("FB is Logged in"); 
      Status.text = "FB is Logged In"; 
     } else { 
      Debug.Log ("FB is not Logged in"); 
      Status.text = "FB is not Logged In"; 
     } 
     DealWithFBMenus (FB.IsLoggedIn); 
    } 
} 

void DealWithFBMenus(bool isLoggedIn){ 
    if (isLoggedIn) { 
     LoggedIn.SetActive (true); 
     LoggedOut.SetActive (false); 
     GoogleAccount.SetActive (false); 
     LocalAccount.SetActive (false); 
     PlayStoreAccount.SetActive (false); 
     FB.API ("/me?fields=first_name", HttpMethod.GET, DisplayUsername); 
     FB.API ("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayProfilePic); 
    } else { 
     LoggedIn.SetActive (false); 
     LoggedOut.SetActive (true); 
     GoogleAccount.SetActive (true); 
     LocalAccount.SetActive (true); 
     PlayStoreAccount.SetActive (true); 
    } 
} 

void DisplayUsername(IResult result){ 
    Text UserName = username.GetComponent<Text>(); 

    if (result.Error == null) { 
     UserName.text = "hi there " + result.ResultDictionary ["first_name"]; 
    } else { 
     Debug.Log (result.Error); 
    } 
} 

void DisplayProfilePic(IGraphResult result){ 
    Image ProfilePic = ProfilePicture.GetComponent<Image>(); 
    if (result.Texture != null) { 

     ProfilePic.sprite = Sprite.Create (result.Texture, new Rect (0, 0, 128, 128), new Vector2()); 

    } else { 

     Destroy (ProfilePic.sprite); 
    } 
} 
} 

Antwort

0

Was ich war

auf meinen Zustand habe

If(isLoggedIn){ //call your login function here fbLogin(); }

Es ist nicht die Sitzung zu lesen, weil ich gerade ein Debug setzen.

Verwandte Themen