【问题标题】:Retrieve gtalk nickname in python xmpp在 python xmpp 中检索 gtalk 昵称
【发布时间】:2010-12-27 14:55:48
【问题描述】:

在 python xmpp 模块中,我可以检索任何联系人的昵称,如下所示:

self.connection.auth(userJid.getNode(), self.password)
self.roster = self.connection.getRoster()  
name = self.roster.getName(buddyJid)

.. buddyJid 的格式为 user@gmail.com。
现在,我需要检索对 connection 进行身份验证的用户的昵称 (userJid)。我找不到使用上述方法的名称。 我可以使用哪种方法来检索当前用户的姓名?

【问题讨论】:

    标签: python xmpppy


    【解决方案1】:

    此信息不在名册中。您需要单独查询客户并通过发送此 IQ 获取他们的 vCard:

    <iq from='stpeter@jabber.org/roundabout'
        id='v1'
        type='get'>
      <vCard xmlns='vcard-temp'/>
    </iq>
    

    【讨论】:

      【解决方案2】:

      谢谢 nicholas_o,这是我根据您的建议整理的示例函数。 (XML 逻辑并不理想,但对于我需要它的简单任务来说已经足够了)

      def vcard(disp, jid):
          msg = xmpp.protocol.Iq()
          msg.setType('get')
          msg.setTo(jid)
          qc = msg.addChild('vCard')
          qc.setAttr('xmlns', 'vcard-temp')
          rep = disp.SendAndWaitForResponse(msg)
          # to see what other fields are available in the XML output:
          # print rep
          userid=fname=lname=title=department=region=None
          for i in rep.getChildren():
              for j in i.getChildren():
                  if j.getName() == "TITLE":
                      title = j.getData().encode('utf-8')
                  for k in j.getChildren():
                      if k.getName() == "GIVEN":
                          fname = k.getData().encode('utf-8')
                      if k.getName() == "FAMILY":
                          lname = k.getData().encode('utf-8')
                      if k.getName() == "ORGUNIT":
                          department = k.getData().encode('utf-8')
                      if k.getName() == "REGION":
                          region = k.getData().encode('utf-8')
          return fname, lname, title, department, region
      

      【讨论】:

        猜你喜欢
        • 2019-06-17
        • 2016-04-01
        • 2011-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多