public void GetProfilePicture(OnFacebookDelegate pPictureCallback) { onGetProfilePictureCallback += pPictureCallback; FB.API(FacebookUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, (FBResult result) => { if (onGetProfilePictureCallback != null) { onGetProfilePictureCallback(result); } onGetProfilePictureCallback = null; }); }
void HandleProfilePicture(FBResult result) { // Check for errors if (result.Error != null) { // If problem occur Debug.Log("Problem with getting the profile picture"); FB.API(FacebookUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, HandleProfilePicture); return; } Image UserAvatar = UIFBAvatar.GetComponent <Image>(); // Facebook will return a texture UserAvatar.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128, 128), new Vector2(0, 0)); }
void HandleFBMenus(bool isLoggedIn) { if (isLoggedIn) { UIFBIsLoggedIn.SetActive(true); UIFBIsNotLoggedIn.SetActive(false); // Get Profile picture FB.API(FacebookUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, HandleProfilePicture); // Get User Name FB.API("/me?fields=id,first_name,middle_name,last_name", Facebook.HttpMethod.GET, HandleUserName); } else { UIFBIsLoggedIn.SetActive(false); UIFBIsNotLoggedIn.SetActive(true); } }
void GetUserInfoCallback(FBResult result) { if (result.Error != null) { Debug.Log("Get username fail"); return; } Debug.Log("GetUserInfoCallback: " + result.Text); string[] fields = new string[] { "id", "name" }; Dictionary <string, string> playerProfile = FacebookUtil.DeserializeJSONProfile(result.Text, fields); // Set Player's avatar and name PlayerAvatar.SetActive(true); PlayerName.SetActive(true); Text username = PlayerName.GetComponent <Text>(); username.text = "Hello, " + playerProfile["name"]; userInfo.userID = string.Copy(playerProfile ["id"]); userInfo.userName = string.Copy(playerProfile ["name"]); List <object> friends = FacebookUtil.DeserializeJSONFriends(result.Text); userInfo.userFriends = ""; for (int i = 0; i < friends.Count; i++) { var friendDict = ((Dictionary <string, object>)(friends[i])); string friendID = (string)friendDict["id"]; userInfo.userFriends += friendID + "|"; } //Get avatar FB.API(FacebookUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, GetAvatarCallback); }
public void SetProfilePicture() { FB.API(FacebookUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, HandleProfilePicture); // Get User Name FB.API("/me?fields=id,first_name,middle_name,last_name", Facebook.HttpMethod.GET, HandleUserName); }