Connecting to Google Talk over XMPP on Node.js
Asked Answered
S

2

11

I've tried using a variety of XMPP libraries for Node.js, and am having trouble connecting to Google Talk's XMPP servers. I'm wanting to connect and read the status of friends, but I can't even get out door!

  1. I have a personal domain hosted through Google Apps for Domains, e.g., mydomain.com.
  2. I've got the following code written - it makes use of the node-xmpp library (https://github.com/astro/node-xmpp):

    jid = '[email protected]';
    password = 'my_google_password';
    
    // Establish a connection
    var conn = new xmpp.Component({
        jid         : jid,
        password    : password,
        host        : 'talk.google.com',
        port        : 5222
    });
    conn.on('online', function(){
        sys.put("ONLINE");        
    });
    conn.on('error', function(e) {
         sys.puts(e);
    });
    

A connection is established, but authentication fails, and I receive this message back from Google Talk:

<stream:error xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
    <not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
</stream:error>

...am I missing something? I've tried other libraries (https://github.com/mwild1/xmppjs), and even a Python library, and still haven't been able to authenticate. I'm 100% sure my Google username and password are correct - any tips/ideas?

Sternutatory answered 3/12, 2010 at 20:28 Comment(2)
btw I believe xmppjs is a component library and can't be used to connect to google.Dogcatcher
maybe you should accept your own answer so that this topic can be closed?Dogcatcher
S
11

Figured it out.

I was working with some inaccurate examples.

In my example above, you'll want to change:

var conn = new xmpp.Component({...})

...to...

var conn = new xmpp.Client({...})
Sternutatory answered 3/12, 2010 at 20:44 Comment(1)
lol oops. Did not read this correct :). You allready solved your problem :)Dogcatcher
D
7

I am on ubuntu linux so to install it I first had to do this(First install node/npm following receipe from npm website).

sudo apt-get install libexpat1 libexpat1-dev 
npm install node-xmpp
sudo apt-get install libicu-dev 
npm install node-stringprep

With this snippet I succesfully logged in and sent a message from my gmail account to my jabber.org account:

var argv = process.argv;
const xmpp = require('node-xmpp');
const sys = require('sys');

if (argv.length != 5) {
    sys.puts('Usage: node xmpp.js <my-jid> <my-password> <to>');
    process.exit(1);
}

const jid = argv[2];
const password = argv[3];
const to = argv[4];

// Establish a connection
const conn = new xmpp.Client({
    jid         : jid,
    password    : password,
    host        : 'talk.google.com',
    port        : 5222
});

conn.on('online', function(){
    console.log('online');

    conn.send(new xmpp.Element('presence'));
    conn.send(new xmpp.Element('message',
        { to: to, // to
            type: 'chat'}).
            c('body').
            t('testje'));
});

conn.on('error', function(e) {
    sys.puts(e);
});
Dogcatcher answered 3/12, 2010 at 23:53 Comment(1)
How I can connect to xmpp without using node-xmpp moduleDefault

© 2022 - 2024 — McMap. All rights reserved.