Facebook C# SDK:BatchAsync 通过一个批处理请求获取所有朋友的最后状态

本文关键字:获取 请求 批处理 朋友 状态 最后 一个 BatchAsync SDK Facebook | 更新日期: 2023-09-27 17:57:21

如何在一个批处理请求中获取所有好友的最后状态?我尝试了以下方法,但它不起作用:

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

Facebook C# SDK:BatchAsync 通过一个批处理请求获取所有朋友的最后状态

我可以使用 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