使用Jabber ID的Facebook连接 [英] Facebook connectivity using Jabber ID

查看:251
本文介绍了使用Jabber ID的Facebook连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,而不是使用SASLAuthentication如X-FACEBOOK平台,我使用Facebook的Jabber代号方法登录。

In my app, Instead of using SASLAuthentication such as X-FACEBOOK-PLATFORM, I'm using Facebook Jabber ID method for login.

这个参考,我得到了下面这段code

From this reference, I got the following piece of code

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)提到有步骤

I used smack 3.3.0 api, uses_INTERNET permission, and the steps mentioned there(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,nizam.cs@facebook.com和放大器; nizam.cs@chat.facebook.com进行登录,但没有这些工作的。

Having profile like www.facebook.com/nizam.cs ; I used user id as nizam.cs, nizam.cs@facebook.com & nizam.cs@chat.facebook.com for login but none of those worked.

我在想什么?

我测试模拟器没有一个Facebook SDK。

I tested it on emulator without a facebook sdk.

推荐答案

问题解决了! :)

问题是与我所用的嫌库。相反smack3.3.0,使用 asmack-Android的6.jar 这是一个更新SMACK库:嫌与xep0280和xep0184

The problem was with the smack library that I used. Instead of smack3.3.0, used asmack-android-6.jar which is an update SMACK library: smack with xep0280 and xep0184.

这解决了连接问题。

这篇关于使用Jabber ID的Facebook连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆