Facebook SDK会话(UNITY)

时间:2017-11-20 07:36:43

标签: android facebook session facebook-graph-api unity3d

我正在使用FACEBOOK SDK 7.4.0版本和Unity 5.6.3P2创建一个LOGIN系统。它成功获取我第一次登录时所需的信息。 我实际上有两个问题与FACEBOOK SDK。

  

1。)当我退出时,它成功返回我的登陆菜单。现在问题发生在这里,因为当我再次尝试登录时它不再起作用它继续像这样弹出。   Like This    2.)当我第一次登录时,它成功获取了我想要的信息,然后当我关闭我的应用程序并重新打开它时。我需要再次点击登录按钮,这不是那样的。就像在FACEBOOK SDK上没有会话一样。

到目前为止,这是我的代码。

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

1 个答案:

答案 0 :(得分:0)

我所做的就是我的情况

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

它没有阅读会话,因为我只是在那里进行调试。