繁体   English   中英

Facebook SDK Unity发布

[英]Facebook SDK Unity Publish

我正在开发一款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

取消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";
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM