Reputation: 4495
I was trying to retrieve wall posts for a particular user, similar question has been answered here - How to get posts of user , but for some strange reasons it is not working for me.
I followed the article in the codeplex documentation - Getting Started with an ASP.NET MVC 3 Website
The AccountController code is similar to https://gist.github.com/899052 and below is the action method which tries to get the posts
var facebookId = long.Parse(User.Identity.Name);
var user = this.repository.Get(facebookId);
var fb = new FacebookWebClient(user.AccessToken);
dynamic result = fb.Get("me/feed");
but I am always getting an empty array in result.data. I am not quite sure about, whether I need to set any permissions, if so how could I do that?
Update :
In the Account Controller, I wasn't requesting the permission in LogOn method, below is the way it could done, which solved the issue
public ActionResult LogOn(string returnUrl)
{
var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current)
{
RedirectUri = GetOAuthCallbackUri()
};
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("state", returnUrl);
parameters.Add("scope", "offline_access,read_stream,user_photos,user_videos,publish_stream");
var loginUri = oAuthClient.GetLoginUrl(parameters);
return Redirect(loginUri.AbsoluteUri);
}
Before that, I was getting an error mentioned in 5.0.9 error on Exchange code for access token but I downloaded latest source code a compiled as answered in that post
Upvotes: 1
Views: 6680
Reputation: 1472
Firstly, ensure you're authorised with the 'read_stream' permission, otherwise you won't be able to access the news feeds.
Secondly, browse to the path...
https://graph.facebook.com/[user_id]/feed?access_token=[access_token]
...after you have received the access token to see if you get the same results.
Upvotes: 2