2

xmpp を使用して Facebook チャットに接続するために、次の SO の質問に示されているガイドラインに従いました。Facebook に接続して正しい数の連絡先を取得できましたが、連絡先を出力すると、それらはすべて乱数 @chat.facebook.com であり、すべてオフラインに戻ります。

Android Facebook チャット サンプル プロジェクト

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

3 に答える 3

1

XMPP ライブラリのバグです。そのための回避策があります。

ステップ 1: XMPP に接続します。

ステップ 2: xmpp を使用して Facebook アカウントにログインします。

ステップ 3:この fql query を使用してオンライン フレンド リストを取得します。

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

次に、アドレスを文字列uid@chat.facebook.com と連結し、XMPP 経由で通信します。

于 2013-01-24T07:50:02.020 に答える
1

読みやすい名前にしたいだけのように聞こえるので、使ってみてください

rosterEntry.getName()

代わりにユーザー名を返します

rosterEntry.getUser()

JIDを返します。

ただし、オフラインの問題についてはわかりません。どのようにチェックしていますか?プレゼンスの変更を取得するには、名簿リスナーを設定する必要があります。

于 2012-10-30T16:22:07.270 に答える
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.

于 2012-10-29T23:48:26.010 に答える