我正在开发一款Android游戏,我将其连接到Facebook。如果用户已连接,他们可以在Facebook墙上发布应用程序。
脚本InteractiveConsole.cs
中的问题当用户点击发布按钮然后点击取消按钮时,我想显示以下消息:“未发布”。
当他们仅点击发布按钮并发布时,我想显示消息:“发布”。
问题是,在这两种情况下,当我决定发布或取消时,它会向我显示消息:GUI上的“发布”。
这是我的代码:
public GUIText guiFeed;
#region FB.Feed() example
public string FeedToId = "";
public string FeedLink = "http://www.google.com";
public string FeedLinkName = "Test";
public string FeedLinkCaption = "Test Caption ";
public string FeedLinkDescription = "Test Deszcription";
public string FeedPicture = "http://www.selfspark.com/wp-content/uploads/Smiley-Face-Button.jpg";
public string FeedMediaSource = "";
public string FeedActionName = "";
public string FeedActionLink = "";
public string FeedReference = "";
public bool IncludeFeedProperties = false;
private Dictionary<string, string[]> FeedProperties = new Dictionary<string, string[]>();
public void CallFBFeed()
{
Dictionary<string, string[]> feedProperties = null;
if (IncludeFeedProperties)
{
feedProperties = FeedProperties;
}
FB.Feed(
toId: FeedToId,
link: FeedLink,
linkName: FeedLinkName,
linkCaption: FeedLinkCaption,
linkDescription: FeedLinkDescription,
picture: FeedPicture,
mediaSource: FeedMediaSource,
actionName: FeedActionName,
actionLink: FeedActionLink,
reference: FeedReference,
properties: feedProperties,
callback: LogCallback
);
}
void LogCallback(FBResult response)
{
Debug.Log(response.Text);
guiFeed.text = "response Feed:"+response.Text;
if (response.Text == null)
{
feedd.text = "not publish";
}
else
{
feedd.text = " publish";
}
}
#endregion
答案 0 :(得分:2)
取消Facebook Share时,cancelled
字段有一个真正的布尔值作为响应。
首先,您应该将字符串中的响应JSON解析为字典,然后您应该检查它是否存在以及它是否为正值,这意味着取消了共享。
您应该像这样更新您的代码:
void LogCallback(FBResult response)
{
var responseObject = Json.Deserialize(response.Text) as Dictionary<string, object>;
object cancelled;
if (responseObject.TryGetValue ("cancelled", out cancelled))
{
if( (bool)cancelled == true )
{
feedd.text = "not publish";
}
else
{
feedd.text = "publish";
}
}
else
{
feedd.text = "publish";
}
}