我正在使用 facebook 和 C# sdk 开发一个 windows phone 7 应用程序,用于从 facebook 朋友那里获取信息。我被困在某个地方...
我可以用这个在 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;
}