在我的应用程序中,我没有使用诸如之类的SASLAuthentication,而是使用Facebook方法进行登录。
从this引用中,我得到了以下代码
public void connectToFb() throws XMPPException {
ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222);
config.setSASLAuthenticationEnabled(true);
config.setSecurityMode(SecurityMode.required);
config.setRosterLoadedAtLogin(true);
config.setTruststorePath("/system/etc/security/cacerts.bks");
config.setTruststorePassword("changeit");
config.setTruststoreType("bks");
config.setSendPresence(false);
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, MemorizingTrustManager.getInstanceList(this), new java.security.SecureRandom());
config.setCustomSSLContext(sc);
} catch (GeneralSecurityException e) {
Log.w("TAG", "Unable to use MemorizingTrustManager", e);
}
XMPPConnection xmpp = new XMPPConnection(config);
try {
xmpp.connect();
xmpp.login("facebookusername", "****"); // Error on this line
Roster roster = xmpp.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
System.out.println("Connected!");
System.out.println("\n\n" + entries.size() + " buddy(ies):");
// shows first time onliners---->
String temp[] = new String[50];
int i = 0;
for (RosterEntry entry : entries) {
String user = entry.getUser();
Log.i("TAG", user);
}
} catch (XMPPException e) {
xmpp.disconnect();
e.printStackTrace();
}
}我使用了smack 3.3.0 api、uses_INTERNET权限以及其中提到的步骤(MemorizingTrustManager)。
但我搞错了。
04-21 15:18:44.589: E/AndroidRuntime(2811): FATAL EXCEPTION: main
04-21 15:18:44.589: E/AndroidRuntime(2811): java.lang.VerifyError: org.jivesoftware.smack.sasl.SASLMechanism
04-21 15:18:44.589: E/AndroidRuntime(2811): at java.lang.Class.getDeclaredConstructors(Native Method)
04-21 15:18:44.589: E/AndroidRuntime(2811): at java.lang.Class.getConstructor(Class.java:472)
04-21 15:18:44.589: E/AndroidRuntime(2811): at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:314)
04-21 15:18:44.589: E/AndroidRuntime(2811): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:221)
04-21 15:18:44.589: E/AndroidRuntime(2811): at org.jivesoftware.smack.Connection.login(Connection.java:366)
04-21 15:18:44.589: E/AndroidRuntime(2811): at com.activapps.fbchat.MainActivity.connectToFb(MainActivity.java:61)拥有类似于www.facebook.com/nizam.cs的配置文件;我使用用户id作为nizam.cs、nizam.cs@facebook.com和nizam.cs@chat.facebook.com进行登录,但这些都没有用。
我遗漏了什么?
我在没有facebook的模拟器上测试了它。
发布于 2013-07-18 12:56:46
问题解决了!:)
问题是我用过的smack库。而不是smack3.3.0,而是使用asmack-android-6.jar ,它是一个更新的SMACK库:带有xep0280和xep0184的smack。
解决了连接问题。
https://stackoverflow.com/questions/17708262
复制相似问题