2013-07-17 61 views
2

在我的應用程序,而不是使用SASLAuthentication,如X-FACEBOOK-PLATFORM,我使用Facebook Jabber ID方法登錄。Facebook連接使用Jabber ID

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(); 
} 
} 

我用咂嘴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,[email protected] & [email protected]登錄,但沒有一個工作。

我錯過了什麼?

我在沒有facebook sdk的模擬器上測試它。

回答

1

問題解決了! :)

問題出在我使用的smack庫上。取而代之的是smack3.3.0,使用了asmack-android-6.jar這是一個更新SMACK庫:用xep0280和xep0184敲擊

解決了連接問題。