从Facebook页面获取带有指定字段的帖子

时间:2013-11-11 00:24:03

标签: c# asp.net facebook

我开发了asp.net网络表单,通过此代码使用我的Facebook应用程序从Facebook页面发布帖子

    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));

此代码返回 all posts with their all fields 但我需要 choose some fields of them not all 我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

你应该真正熟悉Facebook .Net API:http://facebooksdk.net/docs/making-synchronous-requests/

如果你使用它,这里有一个代码来获取Post对象中的某些字段和与帖子相关的图像(如果有的话):

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));

如果您不需要,可以删除图像部分。