问题描述
我正在尝试获取玩家的用户名,然后显示它.
I am trying to get the player's username and then display it.
最近,发生了重大变化; IResult替换FBResult.
Recently, there was a breaking changes; IResult replacement for FBResult.
我能够从IGraphResult而不是FBResult返回纹理来显示配置文件图片,因此我希望Text也可用,但没有.
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.
所以我的问题是,我可以从哪里返回文本?我必须添加任何东西到IGraphResult吗?
So my issue is, where can I return the Text from?Do I have to add anything to the 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.
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"];
}
推荐答案
让我们尝试一下
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();
}
这篇关于从IResult Facebook SDK 7.2.0获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!