xmpp.connect()为facebook chat api提供了异常

时间:2013-10-26 06:17:53

标签: android facebook-chat

我正在尝试从facebook chat api获取好友列表,引用此答案Integrate Facebook chat in android with Asmack API。我无法理解如何获得受信任的商店密码和路径。因此,xmpp.connect()给出了一个异常“无法连接到chat.facebook.com”。有人可以帮忙吗? 在此先感谢: - )

 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("");
            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("username", "password"); // Here you have to used only facebookusername from facebookusername@chat.facebook.com
                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();
            }
            }

0 个答案:

没有答案