得到像facebook帖子的数量,然后将其保存到其他地方

时间:2014-02-14 03:38:21

标签: c# facebook

我正在使用Facebook C#SDK开发一个WP 8应用程序,而现在,我希望得到一个帖子的“像计数”。

这是我的代码,一切都运行良好,但返回值,它始终为“null”,因为like_count.like_count从未分配给。我不知道如何在我的代码中分配它。

该行

like_count.like_count = like_info["total_count"].ToString();

的值为“200”但行

return like_count.like_count;

返回null!

private string GetLikes(string id)
    {
        like_comment like_count = new like_comment();
        FacebookClient fb = new FacebookClient(App.AccessToken);
        fb.GetCompleted += (o, e) =>
        {
            if (e.Error != null)
            {
                Dispatcher.BeginInvoke(()
                    =>
                    MessageBox.Show(e.Error.Message)
                    );
                return;
            }

            var result = (IDictionary<string, object>)e.GetResultData();
            var like_info = (JsonObject)result["summary"];
            Dispatcher.BeginInvoke(()
                =>
                {
                    like_count.like_count = like_info["total_count"].ToString();
                }
                );
        };
        fb.GetTaskAsync("/"+id+"/likes?summary=1");
        return like_count.like_count;
    }

希望有人可以帮助我:(

1 个答案:

答案 0 :(得分:0)

以下不起作用?

private string GetLikes(string id)
{
    FacebookClient fb = new FacebookClient(App.AccessToken);
    fb.GetCompleted += (o, e) =>
    {
        if (e.Error != null)
        {
            Dispatcher.BeginInvoke(()
                =>
                MessageBox.Show(e.Error.Message)
                );
            return;
        }

        var result = (IDictionary<string, object>)e.GetResultData();
        var like_info = (JsonObject)result["summary"];
        Dispatcher.BeginInvoke(()
            =>
            {
                return like_info["total_count"].ToString();
            }
            );
    };
    fb.GetTaskAsync("/"+id+"/likes?summary=1");
}