简体   繁体   English

Facebook SDK会话(UNITY)

[英]Facebook SDK Session(UNITY)

I'm creating a LOGIN system using FACEBOOK SDK 7.4.0 version and Unity 5.6.3P2. 我正在使用FACEBOOK SDK 7.4.0版本和Unity 5.6.3P2创建LOGIN系统。 It successfully gets the information i needed when i first login . 首次登录时,它成功获取了我需要的信息。 I have 2 problems with the FACEBOOK SDK actually. 我的FACEBOOK SDK实际上有2个问题。

1.) When i logout it successfully return to my landing menus. 1.)当我注销时,它成功返回到我的登陆菜单。 Now the problem occurs here because when i try to login again it doesn't work anymore it keeps on popping like this. 现在这里出现问题了,因为当我再次尝试登录时,它不再起作用了,它一直像这样不断弹出。 像这样 2.) When i login for the first time it successfully get the information i wanted then when i close my application and reopen it. 2)当我第一次登录时,它成功获取了我想要的信息,然后当我关闭我的应用程序并重新打开它时。 I will need to click again the login button which is not to be like that. 我将需要再次单击不是这样的登录按钮。 Its like no session on the FACEBOOK SDK. 就像在FACEBOOK SDK上没有会话一样。

Here's my code so far. 到目前为止,这是我的代码。

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

What i did was on my condition 我所做的是我的状况

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

It wasn't reading the session because i was just putting a debug there. 它不是在读取会话,因为我只是在此处进行调试。

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

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