Google Cloud Connection Server and smack

I am trying to configure a Java server to communicate with Google Cloud Connection Server using the smack library. I installed the application key and the API key through the Google API and am trying to use the following code:

import javax.net.ssl.SSLSocketFactory; import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.SASLAuthentication; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Packet; public class CloudMessager { public CloudMessager(){ ConnectionConfiguration config = new ConnectionConfiguration("gcm.googleapis.com", 5235); SASLAuthentication.supportSASLMechanism("PLAIN", 0); config.setSASLAuthenticationEnabled(true); config.setSocketFactory(SSLSocketFactory.getDefault()); Connection connection = new XMPPConnection(config); // Connect to the server try { connection.connect(); connection.login(" SENDERID@gcm.googleapis.com ", "APIKEY"); PacketListener myListener = new PacketListener() { public void processPacket(Packet packet) { } }; // Register the listener. connection.addPacketListener(myListener,null); } catch (XMPPException e) { e.printStackTrace(); } } } 

Which gives me the following error:

 SASL authentication PLAIN failed: text: at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:342) at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:221) at org.jivesoftware.smack.Connection.login(Connection.java:366) at org.umptyfratz.strongbox.CloudMessager.<init>(CloudMessager.java:25) 

I’ll lose a little to figure out where to go from here. Has anyone else successfully connected to CCS using the Java smack library?

+4
source share
1 answer

Try debugging the connection with this option:

 config.setDebuggerEnabled(true); 

This will open a new window with the data sent and received.

If you find something like "Project SENDERID, not a whitelist." You need to register your project here .

(This is also stated in the documentation! Http://developer.android.com/google/gcm/ccs.html )

+3
source

Source: https://habr.com/ru/post/1488201/


All Articles