我正在尝试设置一个 java 服务器,以便使用 smack 库与 Google 的云连接服务器进行通信。我已通过 Google API 设置了应用 ID 和 API 密钥,并尝试使用以下代码:
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();
}
}
}
这给了我以下错误:
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)
我有点不知所措,不知道从这里去哪里。有其他人使用 Java smack 库成功连接到 CCS 吗?