c# - 从具有指定字段的 Facebook 页面获取帖子

标签 c# asp.net facebook

我开发了 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/

相关文章:

c# - Unity - 升级项目后在命名空间 'Rigidbody2D' 中找不到类型名称 'UnityEngine'

c# - 在 .Net 中使用基于 REST 的 Web 服务

iOS:获取 Facebook Graph 请求

javascript - 动态页面和类似 Facebook 的框的解决方法

c# - 我们应该如何向现有变量添加实例化?

c# - .Net Web Api - 覆盖 AuthorizationFilter

c# - 无法获取GridView中Linkbutton的文本

c# list<int> 如何在两个值之间插入一个新值

ios - Facebook 使用 iOS 集成,坏了两天

c# - mysql 存储过程参数似乎不适用于 "@"(At 符号)