I’m having some trouble with a Facebook Login/Share POC I’ve put together for the Unity Web Player. When I run it in the editor everything runs fine. I can login, retrieve profile name and picture and share to wall. When I create a build for Web Player however, nothing functions. Clicking login does nothing and all UI elements show up at start even though in code I’ve set many to be inactive until the login button is clicked. Would really appreciate some help on this, I have no idea why it’s getting built incorrectly. https://locomoku.com/projects/facebook/
public GameObject UIFBIsLoggedIn;
public GameObject UIFBNotLoggedIn;
public GameObject UIFBAvatar;
public GameObject UIFBUserName;
private Dictionary<string, string> profile = null;
void Awake()
{
FB.Init(SetInit, OnHideUnity);
}
private void SetInit()
{
Debug.Log(“FB Init Done”);
if(FB.IsLoggedIn)
{
Debug.Log(“FB Logged in”);
DealWithFBMenus(true);
}
else
{
DealWithFBMenus(false);
}
}
private void OnHideUnity(bool isGameShown)
{
if(!isGameShown)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
public void FBLogin()
{
FB.Login(“public_profile, user_friends”, AuthCallback);
}
void AuthCallback(FBResult result)
{
if(FB.IsLoggedIn)
{
Debug.Log(“FB Login Worked”);
DealWithFBMenus(true);
}
else
{
Debug.Log(“FB Login Fail”);
DealWithFBMenus(false);
}
}
void DealWithFBMenus(bool isLoggedIn)
{
if(isLoggedIn)
{
UIFBIsLoggedIn.SetActive(true);
UIFBNotLoggedIn.SetActive(false);
// Get Profile Picture Code
FB.API(Util.GetPictureURL(“me”,128,128),Facebook.HttpMethod.GET,DealWithProfilePicture);
// Get User Name Code
FB.API(“/me?fields=id,first_name”, Facebook.HttpMethod.GET, DealWithUserName);
}
else
{
UIFBIsLoggedIn.SetActive(false);
UIFBNotLoggedIn.SetActive(true);
}
}
void DealWithProfilePicture(FBResult result)
{
if (result.Error == null)
{
Image img = UIFBAvatar.GetComponent();
img.sprite = Sprite.Create(result.Texture, new Rect(0,0, 128, 128), new Vector2());
}
else{
Debug.Log(“Error with Profile Picture”);
}
}
void DealWithUserName(FBResult result)
{
if (result.Error == null)
{
profile = Util.DeserializeJSONProfile(result.Text);
Text userMsg = UIFBUserName.GetComponent();
userMsg.text = "Hello, " + profile[“first_name”];
}
else{
Debug.Log(“Error with Profile Name”);
}
}
public void ShareWithFriends()
{
FB.Feed(
linkCaption: “Test Captions”,
picture: “https://locomoku.com/projects/facebook/shot.jpg”,
linkName: “Test Link Name”,
link: “http://locomoku.com”
);
}
The Util.cs code
public static string GetPictureURL(string facebookID, int? width = null, int? height = null, string type = null)
{
string url = string.Format(“/{0}/picture”, facebookID);
string query = width != null ? “&width=” + width.ToString() : “”;
query += height != null ? “&height=” + height.ToString() : “”;
query += type != null ? “&type=” + type : “”;
if (query != “”) url += (“?g” + query);
return url;
}
public static void FriendPictureCallback(FBResult result)
{
if (result.Error != null)
{
Debug.LogError(result.Error);
return;
}
//GameStateManager.FriendTexture = result.Texture;
}
public static Dictionary<string, string> RandomFriend(List friends)
{
var fd = ((Dictionary<string, object>)(friends[Random.Range(0, friends.Count - 1)]));
var friend = new Dictionary<string, string>();
friend[“id”] = (string)fd[“id”];
friend[“first_name”] = (string)fd[“first_name”];
return friend;
}
public static Dictionary<string, string> DeserializeJSONProfile(string response)
{
var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
object nameH;
var profile = new Dictionary<string, string>();
if (responseObject.TryGetValue(“first_name”, out nameH))
{
profile[“first_name”] = (string)nameH;
}
return profile;
}
public static List DeserializeScores(string response)
{
var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
object scoresh;
var scores = new List();
if (responseObject.TryGetValue (“data”, out scoresh))
{
scores = (List) scoresh;
}
return scores;
}
public static List DeserializeJSONFriends(string response)
{
var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
object friendsH;
var friends = new List();
if (responseObject.TryGetValue(“friends”, out friendsH))
{
friends = (List)(((Dictionary<string, object>)friendsH)[“data”]);
}
return friends;
}
public static void DrawActualSizeTexture (Vector2 pos, Texture texture, float scale = 1.0f)
{
Rect rect = new Rect (pos.x, pos.y, texture.width * scale , texture.height * scale);
GUI.DrawTexture(rect, texture);
}
public static void DrawSimpleText (Vector2 pos, GUIStyle style, string text)
{
Rect rect = new Rect (pos.x, pos.y, Screen.width, Screen.height);
GUI.Label (rect, text, style);
}