Getting Text from IResult Facebook SDK, 7.2.0

杀马特。学长 韩版系。学妹 提交于 2019-12-22 12:44:31

问题


I am trying to get the player's username and then display it.

Recently, there was a breaking changes; IResult replacement for FBResult.

I was able to return a texture from the IGraphResult instead of FBResult, to display the profile picture, so I expect that the Text would be available as well but no.

So my issue is, where can I return the Text from? Do I have to add anything to the IGraphResult?

Here is the code,

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"];

}

Edited: Okay, I did it. It seems that I can also get the username from the IGraphResult. So, I changed the FBResult to IGraphResult. I changed result.Text to result.RawResult.

Here is the code, for anyone who needs it.

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"];

}

回答1:


Let's try it

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();
}


来源:https://stackoverflow.com/questions/33250518/getting-text-from-iresult-facebook-sdk-7-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!