3

我开发了 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 我该怎么做?

4

1 回答 1

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

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

于 2013-11-15T02:31:45.360 回答