开发者

checking facebook user online status

Im using the facebook api to connect to facebook and get my friend list in a c# winforms application.

FaceBookService1.ConnectToFace开发者_如何学运维book();
FriendList.Friends = FaceBookService1.Friends.GetUserObjects();

while those two lines of code get me the list of friends for the logged in user. Im unable to find out which of those users are currently online. I've checked the entire Facebook.Schema.User type for the same, but to no avail.

Any clues?

Thanks.


Have you looked at this: Get Online Friends

Posting code for future use:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜