XMPP 聊天:访问联系人xmppPy 名册的状态消息
我正在尝试使用 xmpppy 访问我的 google talk 联系人的自定义状态消息。到目前为止,我已经完成了:
import xmpp
import sys
userID = '[email protected]'
password = 'mypassword'
ressource = 'Script'
jid = xmpp.protocol.JID(userID)
jabber = xmpp.Client(jid.getDomain(), debug=[])
connection = jabber.connect(('talk.google.com',5222))
auth = jabber.auth(jid.getNode(), password, ressource)
jabber.sendInitPresence(requestRoster=1)
myroster = jabber.getRoster()
名册对象 myroster 现在包含我的联系人,但不包含自定义状态消息。
myroster.getStatus('[email protected]')
返回 None
查看“原始名册”,我可以看到资源字典是空的
u'[email protected]': {'ask': None, 'resources': {}, 'name': u'Some Name', 'groups': [], 'subscription': u'both'}
奇怪的是我今天已经让它工作了,但我的代码可能略有不同,但我不知道是什么正是我所做的不同......
任何帮助将不胜感激!
干杯,
马丁
I'm trying to access my google talk contacts' custom status messages with xmpppy. I'm made it this far:
import xmpp
import sys
userID = '[email protected]'
password = 'mypassword'
ressource = 'Script'
jid = xmpp.protocol.JID(userID)
jabber = xmpp.Client(jid.getDomain(), debug=[])
connection = jabber.connect(('talk.google.com',5222))
auth = jabber.auth(jid.getNode(), password, ressource)
jabber.sendInitPresence(requestRoster=1)
myroster = jabber.getRoster()
the roster object myroster now contains my contacts, but the custom status message is not included.
myroster.getStatus('[email protected]')
returns None
looking at the 'raw roster', I can see that the resources dictionary is empty
u'[email protected]': {'ask': None, 'resources': {}, 'name': u'Some Name', 'groups': [], 'subscription': u'both'}
The weird thing is that I have gotten this to work today, but I the code might have been slightly different, but I can't figure out what exactly I did differently...
Any help would be greatly appreciated!
Cheers,
Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我发现的一件事,当我第一次开始使用 xmpp 时,我并不清楚这一点。交友是双向的。
使用存在节
(a) 您可以“订阅”您的好友,您的好友也可以返回“已订阅”。
(b) 您的朋友可以“订阅”您,您也可以回复“已订阅”。
如果 (a) 或 (b) 发生,您的朋友就会出现在您的名册中。
如果 (a) 或 (b) 发生,您将出现在您的好友名册中。
然而...
除非您“订阅”您的朋友,否则您将看不到他们的状态 - (a) 必须发生
他们不会看到您的状态,除非他们“订阅”您 - (b) 必须发生。
大多数 XMPP 客户端(pidgin、trillian 等)会在您向您的朋友发送“订阅”消息(在他们向您发送“订阅”消息之后)时自动让您将“订阅”消息发送回给您的朋友。 XMPPPY 并不是开箱即用的。您必须对其进行编码才能执行此操作。
这可以解释为什么您看不到状态。或者,如果这不能涵盖您的情况,则可能对其他人有用。
Here's one thing I've found, which was not clear to me when I first started working with xmpp. Friending is two-way.
Using presence stanzas
(a) You can "subscribe" to your friend, and your friend can return "subscribed".
(b) Your friend can "subscribe" to you, and you can return "subscribed".
Your friend will be in your roster if either (a) or (b) has happened.
You will be in your friends roster if either (a) or (b) has happened.
However...
You will not see their status unless you "subscribe" to your friend - (a) must happen
They will not see your status unless they "subscribe" to you - (b) must happen.
Most XMPP clients (pidgin, trillian, etc) will automatically make you send "subscribe" back to your friend when you send them "subscribed" (after they've sent you "subscribe"). XMPPPY does not do this out of the box. You must code it to do this.
This could explain why you weren't seeing status. Or if this doesn't cover your situation, it might be informative to someone else.
这是一个时间问题。添加一个处理程序:
连接之前。然后确保在循环中调用
jabber.Process()
。问题是,在您的代码中,您有时会在查看名册对象之前收到存在节,有时是在查看名册对象之后。It's a timing issue. Add a handler with:
BEFORE connecting. Then make sure to call
jabber.Process()
in a loop. The issue is that with your code, you'll sometimes receive presence stanzas before you look at the roster object, and sometimes after.