简体   繁体   English

Facebook SDK Unity发布

[英]Facebook SDK Unity Publish

I'm developing an Android game in which I connect to Facebook. 我正在开发一款Android游戏,我将其连接到Facebook。 If the user is connected, they can publish the application on their Facebook wall. 如果用户已连接,他们可以在Facebook墙上发布应用程序。

The problem that in the script InteractiveConsole.cs When the user clicks on the publish button and then the cancel button, I want to show this message: "Not published". 脚本InteractiveConsole.cs的问题当用户单击发布按钮然后单击取消按钮时,我想显示以下消息:“未发布”。 When they click on only the publish button and it is published, I want to show the message :"publish". 当他们仅点击发布按钮并发布时,我想显示消息:“发布”。

The problem is that in both cases, when I decide to either publish or cancel, it shows me the message :"publish" on the GUI. 问题是,在这两种情况下,当我决定发布或取消时,它会向我显示消息:GUI上的“发布”。

Here is my code: 这是我的代码:

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

When Facebook Share is cancelled, there is a true boolean value for cancelled field in response. 取消Facebook Share时,响应中cancelled字段有一个真正的布尔值。

First of all, you should parse response JSON from string to a Dictionary, then you should check whether it exists and whether it is positive value, meaning cancelled share. 首先,您应该将响应JSON从字符串解析为字典,然后您应该检查它是否存在以及它是否为正值,这意味着取消了共享。

You should update your code like this: 您应该像这样更新您的代码:

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