Facebook asmack xmpp客户端返回花名册的随机数 [英] Facebook asmack xmpp client returns random numbers for roster
问题描述
我遵循以下SO问题中提供的指南,使用xmpp连接到Facebook聊天,我可以连接到Facebook并提取正确数量的联系人,但是当它打印联系人时,他们都是随机数@ chat.facebook .com并全部返回离线。
I followed the guidlines given in the following SO question to connect to facebook chat using xmpp and I am able to connect to facebook and pull the correct number of contacts but when it prints the contacts they are all random numbers @chat.facebook.com and all return offline.
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();
}
}
推荐答案
XMPP库中的错误。这有一个工作。
Its a bug in XMPP library . There is a work around for that .
步骤1:连接到XMPP。
步骤2:
Step 2: Login to facebook account through xmpp.
步骤3:使用此fql查询获取在线好友列表。
Step 3: get online friend list using this fql query .
SELECT uid, name, online_presence ,
sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
然后我用string uid@chat.facebook.com连接地址,并通过XMPP。
Then i concat address with string uid@chat.facebook.com and communicate via XMPP.
这篇关于Facebook asmack xmpp客户端返回花名册的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!