开发者

Getting online friends using Jabber (XMPP)

开发者 https://www.devze.com 2023-02-19 22:25 出处:网络
I am facing a problem when communicating with the server: [request]<stream:stream to=\"chat.facebook.com\" xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" version=\"1.0\"

I am facing a problem when communicating with the server:

[request]    <stream:stream to="chat.facebook.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">
[response]    <?xml version="1.0"?><stream:stream id="0D752DF3" from="chat.facebook.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xml:lang="en"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-FACEBOOK-PLATFORM</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms></stream:features>
[request]    <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-FACEBOOK-PLATFORM" />
[response]    <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">[removed]</challenge>
[request]    <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">[r开发者_如何学Cemoved]</response>
[response]    <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
[response]    <?xml version="1.0"?><stream:stream id="4FC996C0" from="chat.facebook.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xml:lang="en"><stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>

[request]    <iq type="set" id="1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" /></iq>
[response]    <iq id="1" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>-[removed]@chat.facebook.com/[removed]</jid></bind></iq>
[request]    <iq type="set" id="2" to="chat.facebook.com"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>
[response]    <iq type="result" from="chat.facebook.com" id="2"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>
[request]    <iq type="get" id="3" from="-[removed]@chat.facebook.com/[removed]"><query xmlns="jabber:iq:roster"/></iq>

The problem is the last request:

[request]    <iq type="get" id="3" from="-[removed]@chat.facebook.com/[removed]"><query xmlns="jabber:iq:roster"/></iq>

Which, according to the documentation [?], should return only online users. However, it returns all user friends instead. How do I get/filter only online users?


The documentation is in RFC 3921 or better yet, RFC 3921bis, which should get an RFC number soon. See section 2.1.3 for details on you retrieve your roster, which is a list of all of your contacts, no matter their presence state. To receive the presence of the people you're subscribed to, you send in your own presence to start the flow.

You send:

<presence/>

and will receive back a presence stanza from each device of each of your online contacts:

<presence from='friend1@example.com/deviceID/>
<presence from='friend2@example.com/deviceID/>

etc. You don't know when you've received "all" of the presence, since your contacts can be changing their presence while this is occurring. Instead, think of stepping into the flow of presence information, where you will be brought up to date as quickly as possible, then be notified of any further changes.


Roster is more or less your contact list (I don't know exact definition), but on Facebook it seems to be quite the same as your friend list. On Facebook chat, server sends you presence information for your friends very quickly after sending initial presence as Joe instructed. Actually I haven't queried roster at all as I'm not interested in friends not online.

0

精彩评论

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