如何在一个批量请求中获取所有朋友的最后状态?我尝试了以下但不起作用:
FacebookClient _FacebookClient = new FacebookClient ( Settings.AccessToken );
FacebookClient.PostCompleted += new EventHandler<FacebookApiEventArgs> ( _FacebookClient_PostCompleted );
FacebookClient.BatchAsync
(
new FacebookBatchParameter [ ]
{
new FacebookBatchParameter( HttpMethod.Get , "/me/friends" , new Dictionary<string , object> { { "fields" , "id , name , picture" } } ) { Data = new { name = "one-friend", omit_response_on_success = false } } ,
new FacebookBatchParameter{ Parameters = new { ids = "{result=one-friend:$.data.0.id}" } },
new FacebookBatchParameter("{result=one-friend:$.data.0.id}/statuses", new Dictionary<string , object> { { "limit" , "1" } , { "data" , "0" } , { "fields" , "message" } } )
}
);
答案 0 :(得分:1)
我可以使用FQL回答你的问题,这在我看来简单得多。我使用了FacebookWebclient,但FacebookClient应该以同样的方式工作。
FacebookWebClient fb = new FacebookWebClient();
string query0 = "SELECT uid2 FROM friend WHERE uid1 = me()"; //here you get the friends list
string query1 = "SELECT uid, message, status_id FROM status WHERE uid IN (SELECT uid2 FROM #query0)"; //here you get the last statuse of each friend (max 50, or max from the last 30 days)
string query2 = "SELECT uid, name FROM user WHERE uid IN (SELECT uid FROM #query1)"; //here you get the user data (in this case the name only)
dynamic result = fb.Query(query0, query1, query2); //all results
dynamic status = result[1][1]; //results of query1
dynamic friend = result[2][1]; //results of query2
for (int i = 0; i < result[1][1].Count; i++)
{
litFeedback.Text += "<a href=\"http://www.facebook.com/profile.php?id=" + status[i].uid + "\" target=\"_blank\">" + friend[i].name + "</a> : "
+ status[i].message + "<br/>" + Environment.NewLine;
}
//if not using .net 4.0:
//var result = (IList<object>)fb.Query(query1, query2);
//var result0 = ((IDictionary<string, object>)result[0])["fql_result_set"];
//var result1 = ((IDictionary<string, object>)result[1])["fql_result_set"];
注意:
http://developers.facebook.com/docs/reference/fql/status/ “状态表仅限于过去30天或50个帖子,以较大者为准。”
当然,你需要权限: friends_status