【问题标题】:Getting Text from IResult Facebook SDK, 7.2.0从 IResult Facebook SDK 7.2.0 获取文本
【发布时间】:2015-10-22 14:43:36
【问题描述】:

我正在尝试获取玩家的用户名,然后显示它。

最近发生了重大变化; FBResult 的 IResult 替换。

我能够从 IGraphResult 而不是 FBResult 返回纹理以显示个人资料图片,因此我希望 Text 也可以使用,但没有。

所以我的问题是,我可以从哪里返回文本? 我必须向 IGraphResult 添加任何内容吗?

这是代码,

void DealWithUserName(FBResult result)
{
    if(result.Error != null)
    {
        Debug.Log ("Problems with getting profile picture");

        FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
        return;
    }

    profile = Util.DeserializeJSONProfile(result.Text);

    Text UserMsg = UIFBUsername.GetComponent<Text>();

    UserMsg.text = "Hello, " + profile["first_name"];

}

编辑: 好的,我做到了。 看来我也可以从 IGraphResult 中获取用户名。 因此,我将 FBResult 更改为 IGraphResult。 我将 result.Text 更改为 result.RawResult。

这里是代码,供需要的人使用。

void DealWithUserName(IGraphResult result)
{
    if(result.Error != null)
    {
        Debug.Log ("Problems with getting profile picture");

        FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
        return;
    }

    profile = Util.DeserializeJSONProfile(result.RawResult);

    Text UserMsg = UIFBUsername.GetComponent<Text>();

    UserMsg.text = "Hello, " + profile["first_name"];

}

【问题讨论】:

    标签: facebook text facebook-unity-sdk


    【解决方案1】:

    让我们试试吧

    private void DealWithUserName(IGraphResult result){
        if (result.ResultDictionary != null) {
            foreach (string key in result.ResultDictionary.Keys) {
                Debug.Log(key + " : " + result.ResultDictionary[key].ToString());
                // first_name : Chris
                // id : 12345678901234567
            }
        }
        Text UserName = UIUserName.GetComponent<Text>();
        UserName.text = "Hello, "+ result.ResultDictionary["name"].ToString();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多