2010-12-03 45 views
11

我試過對Node.js使用各種XMPP庫,並且無法連接到Google Talk的XMPP服務器。我想連接並閱讀朋友的狀態,但我甚至無法離開!通過Node.js上的XMPP連接到Google Talk

  1. 我有通過Google Apps for Domains託管的個人域名,例如mydomain.com
  2. 我有下面的代碼編寫的 - 它利用了節點XMPP庫(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); 
    }); 
    

連接建立,但驗證失敗,我收到此消息從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> 

...我錯過了什麼嗎?我試過其他庫(https://github.com/mwild1/xmppjs),甚至是Python庫,但仍然無法進行身份驗證。我100%確定我的Google用戶名和密碼是正確的 - 任何提示/想法?

+0

順便說一句,我相信xmppjs是一個組件庫,不能用來連接到谷歌。 – Alfred 2010-12-04 00:05:46

+0

也許你應該接受你自己的答案,以便這個話題可以被關閉? – Alfred 2010-12-05 01:40:18

回答

11

想通了。

我正在處理一些不準確的例子。

在我上面的例子中,你會想改變:

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

...到...

var conn = new xmpp.Client({...}) 
+0

lol oops。沒有閱讀這個正確的:)。你已經解決了你的問題:) – Alfred 2010-12-04 00:58:48

7

我在Ubuntu Linux所以安裝它我首先必須這樣做(首先安裝節點/ 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 

在這個片段中我成功地登錄併發送一條消息從我的Gmail帳戶我jabber.org帳戶:

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); 
});