检查Facebook用户的在线状态

时间:2010-03-03 19:40:50

标签: c# winforms facebook

我使用facebook api连接到facebook并在c#winforms应用程序中获取我的朋友列表。

FaceBookService1.ConnectToFacebook();
FriendList.Friends = FaceBookService1.Friends.GetUserObjects();

虽然这两行代码为我提供了登录用户的朋友列表。我无法找出哪些用户目前在线。我已经检查了整个Facebook.Schema.User类型,但无济于事。

任何线索?

感谢。

1 个答案:

答案 0 :(得分:1)

你看过这个:Get Online Friends

发布代码供将来使用:

  public Collection<User> GetOnlineFriends()
  {
      Collection<string> onlineFriends = GetOnlineFriendIds();
      return GetUserInfo(StringHelper.ConvertToCommaSeparated(onlineFriends));
  }

   public Collection<string> GetOnlineFriendIds()
   {
       Collection<string> friendList = new Collection<string>();
       string xml = GetOnlineFriendsXML();
       if (!String.IsNullOrEmpty(xml))
       {
           XmlDocument xmlDocument = LoadXMLDocument(xml);
           XmlNodeList nodeList = xmlDocument.GetElementsByTagName("fql_query_response");
           if (nodeList != null && nodeList.Count > 0)
           {
               XmlNodeList results = xmlDocument.GetElementsByTagName("user");
               foreach (XmlNode node in results)
               {
                   friendList.Add(XmlHelper.GetNodeText(node, "uid"));
               }
           }
       }
           return friendList;
   }

   public string GetOnlineFriendsXML()
   {
       Dictionary<string, string> parameterList = new Dictionary<string, string>(3);
       parameterList.Add("method", "facebook.fql.query");

       if (!string.IsNullOrEmpty(_userId))
       {                
           parameterList.Add("query", 
               String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}",
                              "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=", _userId, ") AND 'active' IN online_presence"));

       }
       else
       {
           throw new FacebookException("User Id is required");
       }
       return ExecuteApiCallString(parameterList, true);
   }