获取我和我的朋友的帖子(Wall Facebook)
Posted
技术标签:
【中文标题】获取我和我的朋友的帖子(Wall Facebook)【英文标题】:Get Posts (Wall Facebook) of me and my friends 【发布时间】:2015-05-10 09:28:30 【问题描述】:我用 https://developers.facebook.com/tools/access_token/
我创建了一个应用程序。我想得到我和我的朋友们的帖子。
我尝试了me/feed
和me/posts
,但我什么也没得到。
我有这个单元测试。
有什么建议吗?
[TestMethod]
public void Basic_using_SDK()
// http://blog.prabir.me/posts/facebook-csharp-sdk-making-requests
var fb = new Facebook.FacebookClient();
var result = (IDictionary<string, object>)fb.Get("4");
var id = (string)result["id"];
var name = (string)result["name"];
var firstName = (string)result["first_name"];
var lastName = (string)result["last_name"];
var link = (string)result["link"];
var username = (string)result["username"];
var gender = (string)result["gender"];
var male = (string)result["locale"];
var parameters = new Dictionary<string, object>();
parameters["fields"] = "id,name";
result = (IDictionary<string, object>)fb.Get("4", parameters);
id = (string)result["id"];
name = (string)result["name"];
dynamic result2 = fb.Get("4");
id = result2.id;
name = result2.name;
firstName = result2.first_name;
lastName = result2.last_name;
link = result2.link;
username = result2.username;
gender = result2.gender;
male = result2.locale;
dynamic parameters2 = new ExpandoObject();
parameters2.fields = "id,name";
dynamic result3 = fb.Get("4", parameters);
id = result3.id;
name = result3.name;
dynamic me = fb.Get("zuck");
firstName = me.first_name;
lastName = me.last_name;
var client = new FacebookClient(AccessToken);
dynamic me2 = client.Get("me");
string aboutMe = me2.about;
dynamic result4 = client.Get("/me/feed");
foreach (dynamic post in result4.data)
var fromName = post.from.name;
Console.WriteLine(fromName);
dynamic result5 = client.Get("/me/posts");
for (int i = 0; i < result5.Count; i++)
// https://www.facebook.com/profile.php?id=xxxxxxx
// https://graph.facebook.com/xxxxxxx
var uidKiquenet = "xxxxx";
var query = string.Format(@"SELECT status_id,message,time,source,uid,place_id
FROM status WHERE uid IN (SELECT uid FROM status WHERE uid = '" + uidKiquenet + "') ORDER BY time DESC");
dynamic parameters6 = new ExpandoObject();
parameters6.q = query;
dynamic results6 = fb.Get("/xxxxx?fields=id,name,age_range,about,email,first_name,gender");
string myMessage = "Hello from Test";
fb.PostTaskAsync("me/feed", new message = myMessage ).ContinueWith(t =>
if (!t.IsFaulted)
string message = "Great, your message has been posted to you wall!";
Console.WriteLine(message);
);
fb.GetTaskAsync("me").ContinueWith(t =>
if (!t.IsFaulted)
var result11 = (IDictionary<string, object>)t.Result;
string myDetails = string.Format("Your name is: 0 1 and your Facebook profile Url is: 3",
(string)result11["first_name"], (string)result11["last_name"],
(string)result11["link"]);
Console.WriteLine(myDetails);
);
// This uses Facebook Query Language
// See https://developers.facebook.com/docs/technical-guides/fql/ for more information.
query = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=0) ORDER BY name ASC", "me()");
fb.GetTaskAsync("fql", new q = query ).ContinueWith(t =>
if (!t.IsFaulted)
var result1 = (IDictionary<string, object>)t.Result;
var data = (IList<object>)result1["data"];
var count = data.Count;
var message = string.Format("You have 0 friends", count);
Console.WriteLine(message);
foreach (IDictionary<string, object> friend in data)
Console.WriteLine((string)friend["name"]);
);
【问题讨论】:
您确实知道 FQL 已被弃用,并且不再适用于较新的应用程序,对吧?无论如何,您是否使用具有正确权限的用户访问令牌? 审核状态 developers.facebook.com/apps/xxxxx/review-status 我的应用(开发中)默认权限为:email、public_profile、user_friends 不知道为什么要通过审核流程,而您的应用甚至还没有完成...... 用于测试目的 您为什么要通过审查流程进行测试?你没看文档吗? 【参考方案1】:您必须获得正确的权限才能访问摘要帖子。尝试使用user_posts
进行授权,如文档中所述:https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed#read
请注意,这不会让您访问朋友的帖子,除非他们发布在授权用户的墙上。
关于评论,您可能想阅读以下内容:https://developers.facebook.com/docs/facebook-login/review/faqs#what_is_review
顺便说一句,FQL 已弃用,仅适用于 v2.0 应用程序 - 不适用于较新的应用程序。
【讨论】:
【参考方案2】:同样的事情发生在我身上。这是我的解决方案
我在 Facebook 开发者控制台上注册了我的项目。然后我做了和你一样的代码,但无法获得帖子/信息。一段时间后,我向 facebook 团队提交了我的应用程序审查申请(它仍处于早期开发阶段),在他们的反馈之后,我让我的代码正常工作。因此,未决的申请审查也可能是您的问题。此选项在应用程序设置中可用。试一试
更新 另一个代码示例在这里
if (Request["code"] == null)
Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id=0&redirect_uri=1&scope=2",
FB_app_id, Request.Url.AbsoluteUri, FB_scope));
return false;
else
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id=0&redirect_uri=1&scope=2&code=3&client_secret=4&perms=status_update"
, FB_app_id, Request.Url.AbsoluteUri, FB_scope, Request["code"].ToString(), FB_secret_id);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
StreamReader rd = new StreamReader(response.GetResponseStream());
string vals = rd.ReadToEnd();
foreach (string token in vals.Split('&'))
tokens.Add(token.Substring(0, token.IndexOf('=')), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf('=') - 1));
string access_token = tokens["access_token"];
Session["fb_access_token"] = access_token;
return true;
【讨论】:
ASPX 页面中的示例,而不是单元测试?需要响应、请求? 使用它们没有问题,我使用的是cshtml文件而不是aspx文件以上是关于获取我和我的朋友的帖子(Wall Facebook)的主要内容,如果未能解决你的问题,请参考以下文章
Feed Like对话框上的Facebook Like Button帖子消失了
是否有可能从 facebook 图形 API 中不是我的页面中的某个帖子中获取诸如反应或喜欢之类的信息?
Facebook-Ios 获取我刚刚在帖子中标记的用户数量,一些问题