在C#上使用Facebook SDK检索Facebook Wall帖子

时间:2014-02-13 21:12:31

标签: c# facebook facebook-graph-api sdk facebook-c#-sdk

我已经看过几个类似的东西,但找不到我想要的东西,我正在尝试使用Facebook SDK检索wallposts,(比如10个帖子),但到目前为止我所能找到的是如何发布在墙上或hove登录并获取公共用户数据。

这就是我迄今为止的代码老虎机:

public void facebookClientSetup()
    {
        System.Windows.Forms.MessageBox.Show("WOOO STUFF is happening!");
        var fbclient = new FacebookClient("Token|secret");
        dynamic me = fbclient.Get("/me/feed");

        foreach (dynamic post in me.data)
        {
            System.Windows.Forms.MessageBox.Show(post.from.name);
        }
    }

我有这个,但它似乎没有做到。

我错过了什么吗? 还有另一种方法吗?

1 个答案:

答案 0 :(得分:3)

你可以尝试如下......希望它有所帮助

class Posts
{
    public string PostId { get; set; }
    public string PostStory { get; set; }
    public string PostMessage { get; set; }
    public string PostPicture { get; set; }

    public string UserId { get; set; }
    public string UserName { get; set; }

}

 try
        {
//all the posts and their information (like pictures and links) is strored in result.data


            var client = new FacebookClient(token);
            dynamic result = client.Get("/me/posts");
            List<Posts> postsList = new List<Posts>();

            for (int i = 0; i < result.data.Count; i++)
            {
                Posts posts = new Posts();

                posts.PostId = result.data[i].id;
                if (object.ReferenceEquals(result.data[i].story, null))
                    posts.PostStory = "this story is null";
                else
                    posts.PostStory = result.data[i].story;
                if (object.ReferenceEquals(result.data[i].message, null))
                    posts.PostMessage = "this message is null";
                else
                    posts.PostMessage = result.data[i].message;

                posts.PostPicture = result.data[i].picture;
                posts.UserId = result.data[i].from.id;
                posts.UserName = result.data[i].from.name;

                postsList.Add(posts);
            }

        }
        catch (Exception)
        {
            throw;
        }

如果你想要高级选项可以托盘FQL HereHere