1

我正在处理 Facebook 聊天,并且代码在连接到 chat.facebook 之前运行良好。

bt1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            TAG = ed1.getText().toString();
            try {
                testlogin();

            } catch (Exception e) {

                e.printStackTrace();
            }

        }
    });

方法是:

private void testLogin() {
    ConnectionConfiguration config = new ConnectionConfiguration(
            "chat.facebook.com", 5222);
    config.setSASLAuthenticationEnabled(true);
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
    xmpp = new XMPPConnection(config);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        config.setTruststoreType("AndroidCAStore");
        config.setTruststorePassword(null);
        config.setTruststorePath(null);
    } 
    else {
        config.setTruststoreType("BKS");
        String path = System.getProperty("javax.net.ssl.trustStore");
        if (path == null)
            path = System.getProperty("java.home") + File.separator + "etc"
                + File.separator + "security" + File.separator
                + "cacerts.bks";
        config.setTruststorePath(path);
    }
    SASLAuthentication.registerSASLMechanism("X-facebook-PLATFORM",
            SASLXFacebookPlatformMechanism.class);
    SASLAuthentication.supportSASLMechanism("X-facebook-PLATFORM", 0);
    Log.i("XMPPClient", "Access token to " + mFacebook.getAccessToken());
    Log.i("XMPPClient", "Access token to " + mFacebook.getAppId());
    Log.i("XMPPClient", "Access token to " + mFacebook.getAccessToken());
    try {
        xmpp.connect();
        Log.i("XMPPClient", "Connected to " + xmpp.getHost());

    } catch (XMPPException e1) {
        Log.i("XMPPClient", "Unable to " + xmpp.getHost());

        e1.printStackTrace();
    }
    try {
        xmpp.login(mFacebook.getAppId(), mFacebook.getAccessToken()); // error point
        Log.i("XMPPClient", " its logined ");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

后来我向 xmpp.login(,) 提供了 APPid 以及有效的访问令牌,但给出了一个例外:

  07-15 01:47:26.929: W/System.err(12719): SASL authentication failed using mechanism    DIGEST-MD5: 
  07-15 01:47:26.929: W/System.err(12719):  at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:342)
  07-15 01:47:26.929: W/System.err(12719):  at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:230)
  07-15 01:47:26.939: W/System.err(12719):  at org.jivesoftware.smack.Connection.login(Connection.java:353)
  07-15 01:47:26.939: W/System.err(12719):  at com.example.checking.MainActivity.testLogin(MainActivity.java:320)
  07-15 01:47:26.939: W/System.err(12719):  at com.example.checking.MainActivity.access$0(MainActivity.java:279)
  07-15 01:47:26.939: W/System.err(12719):  at com.example.checking.MainActivity$userDetailFB.onPostExecute(MainActivity.java:238)
  07-15 01:53:24.419: W/System.err(12885):  at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:239)
4

0 回答 0