prabirshrestha / FacebookSharp

Facebook Graph API for .Net
Other
30 stars 15 forks source link

Messages from a wall! #21

Open shaneae opened 13 years ago

shaneae commented 13 years ago

How can i get the the messages on the wall of a user?

prabirshrestha commented 13 years ago

var fb = new Facebook("access_token");

var feeds = fb.GetFeeds("me",null); var posts = fb.GetPosts("me",null);

make sure u add "using Facebook.Extensions;" too

shaneae commented 13 years ago

Thank you for the response! Now i'm having a several problems: 1) I'm trying to access the messages on the wall one by one, like this PostCollection posts = fb.GetPosts("me", null); foreach (Post p in posts){} but the foreach give me an error: "foreach statement cannot operate on variables of type 'FacebookSharp.Schemas.Graph.PostCollection' because 'FacebookSharp.Schemas.Graph.PostCollection' does not contain a public definition for 'GetEnumerator'" How can i solve this?

2) How can i get a connection with facebook without an experation time? 3) How do I force the user to enter his email and password every time he tries to connect to facebook?

prabirshrestha commented 13 years ago

try

foreach(var p in posts.Data){
}

and incase you haven't been aware the mergin of FacebookSharp with Facebook C# SDK, I strongly recommend you to read "The State of .Net Facebook Development" - http://ntotten.com/2010/11/the-state-of-net-facebook-development/

prabirshrestha commented 13 years ago

and i you want to get without expiration time, make sure you pass the extended permissions as "offline_access"

shaneae commented 13 years ago

What is the string id?

prabirshrestha commented 13 years ago

extended permissions is specified in readme.md file. https://github.com/prabirshrestha/FacebookSharp/blob/master/README.md

here is an extract from it.

You can specify extened permissions by specifying it in the FacebookSettings.

fbSettings.DefaultApplicationPermissions = new[] { "publish_stream","create_event" } }; Please refer to http://developers.facebook.com/docs/authentication/permissions for more information on extended permissions.

In your case you will need to pass "offline_access" also. The DefaultApplicationPermissions must be during authorization process (getting the access token).

shaneae commented 13 years ago

Thank you for the quick response it help me a lot :) Now another thing what is the string id? on the fb.GetFeeds("me",null); ?

prabirshrestha commented 13 years ago

there are 3 types of id's in facebook.

  1. "12345"
  2. "12345_6789"
  3. "me"

me is a special type of id, which represents the user/page who is using the access token.

with the given senario: Username id access_token A 1 a5 B 2 b6

when i call var fb = new Facebook("a5"); "me" would refer to 1

but if i do new Facebook("b6"); "me" would refer to 2.

"me" is a special id which represents the user/page with the access token u specified.

var fb = new Facebook("a5"); fb.GetFeeds("me",null);

means get the feeds for the user/page whose access_token is a5.

all are mentioned on facebook documentations. its explained in more deatils there.

shaneae commented 13 years ago

I want to get al the names of l the posts on the user wall :

FacebookSharp.Facebook fb = new FacebookSharp.Facebook(facebookAccessToken);

        PostCollection posts = fb.GetPosts("me", null);

        foreach (var p in posts.Data)
        {
            Console.WriteLine(p.Name);
        }

but the cont on the foreach wallways conts 0. How can i resolve this?

shaneae commented 13 years ago

Thank You. I just resolve the problem. But i realise that is not what i realy want. I want to get all the the information like in the user 'Home' tab. It is possible?