1

我正在使用 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;
    }
4

1 回答 1

0

SELECT friend_count, name FROM user WHERE uid = me()

应该给你你正在寻找的东西。但是,根据我的经验,如果您想汇总数据,则最好使用循环。该friend_count列将为您提供一个总数,但也包括非活动、禁用或放弃的帐户。

于 2012-10-27T05:35:15.247 回答