Using smack with google hangout?

Hello,

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("gmail.com") //           .setHost("xmpp.l.google.com") //           .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(Base64.java:64)      at org.jivesoftware.smack.util.stringencoder.Base64.encode(Base64.java:60)      at org.jivesoftware.smack.util.stringencoder.Base64.encodeToString(Base64.java:42)      at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(EntityCapsManager.java:707)      at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(EntityCapsManager.java:581)      at org.jivesoftware.smackx.caps.EntityCapsManager.updateLocalEntityCaps(EntityCapsManager.java:477)      at org.jivesoftware.smackx.caps.EntityCapsManager.(EntityCapsManager.java:309)      at org.jivesoftware.smackx.caps.EntityCapsManager.getInstanceFor(EntityCapsManager.java:374)      at org.jivesoftware.smackx.caps.EntityCapsManager$1.connectionCreated(EntityCapsManager.java:115)      at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.java:649)      at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:851)      at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:364)      at poc.Hangout.main(Hangout.java:35)

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 https://www.opennms.org/wiki/Xmpp_google_hangouts 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.