示例#1
0
    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);
    }
示例#2
0
    void HandleUserName(FBResult result)
    {
        // Check for errors
        if (result.Error != null)
        {
            // If problem occur
            Debug.Log("Problem with getting the user name");
            FB.API("/me?fields=id,first_name,last_name", Facebook.HttpMethod.GET, HandleUserName);
            return;
        }
        profile = FacebookUtil.DeserializeJSONProfile(result.Text);
        Text UserMsg = UIFBUserName.GetComponent <Text>();

        if (profile.Count == 2)
        {
            UserMsg.text = profile["first_name"] + " " + profile["last_name"];
        }
        else
        {
            UserMsg.text = profile["first_name"] + " " + profile["middle_name"] + " " + profile["last_name"];
        }
    }