1
我正在開發一個帶有Facebook和C#sdk的windows phone 7應用程序,用於從Facebook好友那裏獲取信息。我被困在某處...使用fql -facebook獲取friend_count s#sdk
我可以在這個foreach循環中得到一個朋友計數,但是當我從另一個函數調用該函數時,它會返回0.爲什麼?
private object GetFriendsCount() {
var fb = new FacebookClient(_accessToken);
var query = string.Format("SELECT friend_count FROM user WHERE uid={0}", "me()");
// var query1 = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0})", "me()");
fb.GetAsync("fql", new { q = query });
object returnVal = 0;
fb.GetCompleted += (o, e) =>
{
if (e.Error != null)
{
Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
return;
}
var result = (IDictionary<string, object>)e.GetResultData();
var data = (IList<object>)result["data"];
foreach (var comment in data.Cast<IDictionary<string, object>>())
{
returnVal = comment["friend_count"];
// Dispatcher.BeginInvoke(() => MessageBox.Show(returnVal.ToString()));
}
};
return returnVal;
}
我可以得到foreach循環中的friend_count,但問題是我不能從函數返回它,它總是返回0後調用返回returnVal; –
問題是由我解決的,無論如何。 這裏是代碼,也許對其他人有幫助:[link](http://pastebin.com/BSUmB0ch) –