Get name of currently authenticated user

Get name of currently authenticated user

Problem

Is it possible to get the name of the currently authenticated user from the Google Talk XMPP API? I know that it’s possible to get the name of your contacts by using this, but it doesn’t return your name, just your contacts.

P.S. I’m using the node-xmpp module to connect with the API.

Problem courtesy of: Nathaniel

Solution

You can request your own Vcard and get your name from the response when it was set before. See: http://xmpp.org/extensions/xep-0054.html

Example:

<iq id='get_vcard'        
    type='get'>
  <vCard xmlns='vcard-temp'/>
</iq>

<iq id='get_vcard'
    to='your_full_jid'
    type='result'>
  <vCard xmlns='vcard-temp'>
    <FN>Your Full Name</FN>
    <N>
      <FAMILY>Familiy Name</FAMILY>
      <GIVEN>Given Name</GIVEN>
      <MIDDLE/>
    </N>
    <NICKNAME>nickname</NICKNAME>
  </vCard>
</iq>
Solution courtesy of: Alex

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *