Facebook asmack xmpp客户端返回名册的随机数

时间:2012-10-26 01:31:34

标签: android facebook xmpp asmack

我按照以下SO问题中给出的指导来连接到使用xmpp的Facebook聊天,我能够连接到Facebook并提取正确数量的联系人但是当它打印出联系人时它们都是随机数字@ chat.facebook .com和所有人都离线返回。

Android Facebook chat example project

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("user.name", "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();
        }
        }

3 个答案:

答案 0 :(得分:1)

听起来你只想读取名字,所以试试

rosterEntry.getName()

返回用户名,而不是

rosterEntry.getUser()

返回JID。

不确定您的离线问题。你好吗?您必须设置roster listener才能在状态下进行更改。

答案 1 :(得分:1)

它是XMPP库中的一个错误。有一个解决方法。

第1步:连接到XMPP。

第2步:通过xmpp登录Facebook帐户。

第3步:使用此fql查询获取在线好友列表。

    SELECT uid, name, online_presence ,
      sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

然后我用字符串 uid@chat.facebook.com 连接地址,并通过XMPP进行通信。

答案 2 :(得分:0)

(关于在线/离线事情可能是一个错误或者您正在做错误的事情,这并不是100%清楚,但你不会在回复中找回用户的实际用户ID,这在文档中提到:

The user's own Jabber ID (JID) is different from the Jabber ID that their contacts will see because the translation is done internally.

相关问题