xmpp - Smack 连接到 Google 的 XMPP 服务 (gtalk) 会引发异常 "SASLError using PLAIN: not-authorized"

标签 xmpp smack google-talk

我正在尝试使用 SMACK API 连接到 gmail,但出现以下错误,并且过去 2 天我被困住了。

Exception in thread "main" org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:348)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.login(XMPPTCPConnection.java:244)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:442)

我正在使用 smack 4.0.3 jar 和 Java 7。我的办公网络中没有阻止 gmail。我已经厌倦了论坛中给出的所有建议。

1. setting SASLMechanism to PLAIN / DIGEST-MD5.   
2. adding the Thread.sleep delay after connect.  
3. by setting the dummy SSLSocketFactory. 
4. removing the domain name from user name. 

以下是我正在尝试执行的代码。

public class JabberExample {
public static void main(String[] args) throws Exception{

    XMPPTCPConnection con = new XMPPTCPConnection("gmail.com");
    SASLAuthentication.supportSASLMechanism("PLAIN",0);

    con.connect();
    con.login("username", "password");

    Chat chat = ChatManager.getInstanceFor(con).createChat("chatusernam@gmail.com", new MessageListener() {
         public void processMessage(Chat chat, Message message) {
             System.out.println("Received message: " + message);
         }
     });

    chat.sendMessage("Message..!!");

     con.disconnect();
}

}

希望我能在这里得到一些建议和帮助。

最佳答案

Google 最近已转为不允许在其帐户中使用 PLAIN 和类似方法 - https://support.google.com/accounts/answer/6010255 .

如果您想使用此类身份验证机制,帐户将需要启用它们 - https://www.google.com/settings/security/lesssecureapps

关于xmpp - Smack 连接到 Google 的 XMPP 服务 (gtalk) 会引发异常 "SASLError using PLAIN: not-authorized",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25543828/

相关文章:

java - pubsub 发布到节点成功,从节点检索失败

android - 如何使用 Smack 了解 XMPP openfire 中的键入状态

Android 注册 GTalk 传入聊天

python - 如何使用 Twisted Words Python 库创建一个简单的 Google Talk 客户端?

mono - 为什么我无法在 agsXMPP 中连接到 Google Talk?

android - 使用 Smack 库构建、验证和解析

xmpp - 当 Corp 阻止此功能时,如何保存 Lync 对话历史记录?

ios - 在 iphone 中使用 XMPP 创建自定义节

android - 如何使用 smack 库从 ejbbered 服务器获取 LastActivity?

java - GWT - 从 GWT 应用程序连接到 talk.google.com