Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Posts from Facebook page with specified fields

I developed asp.net web form that takes posts from facebook pages using my facebook application by this code

    var client = new WebClient();
    string oauthUrl = string.Format("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={0}&client_secret={1}", "appid", "appsecret");

    string accessToken = client.DownloadString(oauthUrl).Split('=')[1];

    string pageInfo = client.DownloadString(string.Format("https://graph.facebook.com/Mypage?access_token={0} ", accessToken));
    string pagePosts = client.DownloadString(string.Format("https://graph.facebook.com/Mypage/posts?access_token={0} ", accessToken));

this code returns all posts with their all fields but I need to choose some fields of them not all How can I do that??

like image 253
Feras Salim Avatar asked Jul 02 '26 20:07

Feras Salim


1 Answers

you should really familirize yourself with Facebook .Net API: http://facebooksdk.net/docs/making-synchronous-requests/

if you use it, here is a code to get certain fields from Post objects and images associated with the post (if any):

var client = new FacebookClient(accessToken);
var query = string.Format(@"{{ 
""posts"":""SELECT post_id, actor_id, attachment, permalink, app_data, type, likes.count,comments.count,message,source_id ,updated_time,created_time FROM stream WHERE source_id = {0} and updated_time > {1} and type > 0 LIMIT 100"", 
""photo_posts"":""SELECT photo_id, src, width, height FROM photo_src WHERE photo_id in (SELECT attachment.media.photo.fbid FROM #posts where type=247) and width > 300 and width < 500 order by width desc""}}",  userId, LongExtensions.DateTimeToUnixTimestamp(expirationDate.DateTime));

dynamic parameters = new ExpandoObject();
parameters.q = query;

IList<dynamic> postsRaw = ObjectExtensions.ToData(this.client.Get("fql", parameters));

you can remove image part if you don't need it.

like image 101
avs099 Avatar answered Jul 04 '26 10:07

avs099



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!