Reputation: 13
I've seen a couple of similar things but could not find what I was looking for, I am trying to retrieve wallposts, (like 10 last posts) using Facebook SDK, but so far all I could find is how to post on a wall or hove to log in and get public user data.
This is what I have so far code vise:
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);
}
}
I have this but it doesnt seem to quite do it.
Am I missing something? Is there another way to do this?
Upvotes: 1
Views: 6942
Reputation: 92
You can try as follows...hopefully it helps
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;
}
if you want advanced options can tray FQL Here and Here
Upvotes: 3