Question

I am trying to connect to gmail using SMACK API through XMPP server. but getting the

error : SASL authentication failed using mechanism PLAIN

you can check a glimpse of code. I got it from net only

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

I checked in the smack debug window. it says in XML :

< invalid-authzid />

I am already having account on gmail and my gtalk is also running.

Was it helpful?

Solution

You need to set the authentication before you connect viz

SASLAuthentication.supportSASLMechanism("PLAIN", 0);

must appear before connection.connect().

See my blog.

OTHER TIPS

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

I also get this mistake, but i can not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top