我正在尝试通过XMPP服务器使用SMACK API连接到Gmail。但是得到

错误:SASL身份验证使用机制平原失败

您可以查看代码的瞥见。我只从网上得到

ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(connConfig);
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);

我检查了Smack调试窗口。它在XML中说:

<无效的authzid />

我已经在Gmail上有帐户,我的GTALK也在运行。

有帮助吗?

解决方案

您需要在连接之前设置身份验证

SASLAuthentication.supportSASLMechanism("PLAIN", 0);

必须在之前出现 connection.connect().

看到我的 博客.

其他提示

    ConnectionConfiguration cc = new ConnectionConfiguration(
            "vietnam.agilemobile.com", 5222, vietnam.agilemobile.com");
    XMPPConnection connection = new XMPPConnection(cc);
    try {
        SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        connection.connect();
        Log.e("LOGIN", "" + 111);
        // You have to put this code before you login
        Log.e("LOGIN", "" + 222);
        // You have to specify your gmail addres WITH @gmail.com at the end
        connection.login("nemodo", "123456", "resource");
        Log.e("LOGIN", "" + 333);
        // See if you are authenticated
        System.out.println(connection.isAuthenticated());

    } catch (XMPPException e1) {
        e1.printStackTrace();
    }

我也遇到了这个错误,但我无法工作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top