私は、FACEBOOK SDK 7.4.0バージョンとUnity 5.6.3P2を使用してログインシステムを作成しています。それは正常に私が最初にログインするときに必要な情報を取得します。 実際にFACEBOOK SDKに2つの問題があります。Facebook SDKセッション(UNITY)
1.)私は正常に私のランディングメニューに戻ります。ここで問題が発生します。なぜなら、もう一度ログインしようとすると、もう動作しないため、このようにポップし続けるからです。 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);
}
}
}