Using smack with google hangout?


I’m trying to build a java application that sends messages through Hangout.

I’ve looked at smack which seems to answer to my problem, but the initial setup is kind of tricky, there’s a lot dependencies and the behavior change when I add some libs.

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder() //           .setUsernameAndPassword("<username>", "<password>") //           .setServiceName("") //           .setHost("") //           .setPort(5222) //           .setHostnameVerifier(new HostnameVerifier() {                @Override                public boolean verify(String hostname, SSLSession session) {                     return true;                }           }) //           .build();  AbstractXMPPConnection connection = new XMPPTCPConnection(config); connection.connect();

With only smack-core and smack-tcp, the application manage to connect (at least no error is shown).

When I add smack-extension, for sending a message, the above code fail with this strange error:

Exception in thread "main" java.lang.NullPointerException      at org.jivesoftware.smack.util.stringencoder.Base64.encode(      at org.jivesoftware.smack.util.stringencoder.Base64.encode(      at org.jivesoftware.smack.util.stringencoder.Base64.encodeToString(      at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(      at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(      at org.jivesoftware.smackx.caps.EntityCapsManager.updateLocalEntityCaps(      at org.jivesoftware.smackx.caps.EntityCapsManager.(      at org.jivesoftware.smackx.caps.EntityCapsManager.getInstanceFor(      at org.jivesoftware.smackx.caps.EntityCapsManager$1.connectionCreated(      at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(      at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(      at org.jivesoftware.smack.AbstractXMPPConnection.connect(      at poc.Hangout.main(

Can somebody help me through this setup ?

You can’t reach people on Hangouts via Google’s XMPP API AFAIK.

The NPE is because you did not properly initialize Smack. You need to either add smack-java7 or smack-android to your maven dependencies (and drop smack-core).

I found on this page that someone is using smack to connect to google hangout for creating an alert channel.

I didn’t want to deep dive into a complex code as I just wanted a simple api call to test the feasibility.

Thank you for smack initialization, I have a different error now (timeout), I will continue my investigation.

Too bad this is not specified on the getting started page as it seems necessary to get started

Ahh, I wanted to say that you can’t reach people in a “hangout”, i.e. a groupchat, via the XMPP API. You can still send XMPP messages to individual users by using their gmail address as recipient.

I prefer this.

I’m still having trouble as the server doesn’t respond. I’ll focus on other part of my application before returning to this problem.