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.
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();
}
}
Its a bug in XMPP library . There is a work around for that .
Step 1: Connect to XMPP.
Step 2: Login to facebook account through xmpp.
Step 3: get online friend list using this fql query .
Then i concat address with string uid@chat.facebook.com and communicate via XMPP.
It sounds like you just want to readable name, so try using
which returns the users name, instead of
which returns the JID.
Not sure about your offline problem though. How are you checking? You have to set up a roster listener to get changes in presence.
(It's not 100% clear what problem you're having regarding the online/offline thing may be a bug or something you're doing incorrectly), but you won't get back the user's actual user IDs in the response, this is mentioned in the docs:
The user's own Jabber ID (JID) is different from the Jabber ID that their contacts will see because the translation is done internally.