我开发了 asp.net web 表单,通过此代码使用我的 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));
此代码返回所有帖子及其所有字段
但我需要选择其中的一些字段而不是全部
我该怎么做??
最佳答案
您真的应该熟悉 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));
如果你不需要它,你可以删除图像部分。
关于c# - 从具有指定字段的 Facebook 页面获取帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19897016/