- Home /
This question was
closed Feb 26, 2018 at 05:13 AM by
Ginxx009 for the following reason:
The question is answered, right answer was accepted
Facebook SDK Session(UNITY)
I'm creating a LOGIN system using FACEBOOK SDK 7.4.0 version and Unity 5.6.3P2. It successfully gets the information i needed when i first login . I have 2 problems with the FACEBOOK SDK actually.
2.) When i login for the first time it successfully get the information i wanted then when i close my application and reopen it. I will need to click again the login button which is not to be like that. Its like no session on the FACEBOOK SDK.When i logout it successfully return to my landing menus. Now the problem occurs here because when i try to login again it doesn't work anymore it keeps on popping like this.
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);
}
}
}
screenshot-2017-11-20-15-30-27-091.png
(79.1 kB)
Comment