4
我想獲得一個java服務器設置爲使用smack庫與谷歌的雲連接服務器進行通信。我已經設置了通過谷歌的API的應用程序ID和API密鑰,並正在嘗試使用下面的代碼:谷歌雲連接服務器和smack
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("[email protected]", "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?
我有:(你有沒有設法解決這個同樣的問題? – bentzy
Benny-還沒有,我要去嘗試,找到一個妥善的谷歌聯繫人看看他們是否可以告訴我發生了什麼事 – gunglefunk
您是否進一步瞭解 - 我的確有相同的信息。順便說一句:您確定用戶名是[email protected],而不僅僅是SENDERID? –