0

I have a FB chat client developed for Android. I've been using facebook android-sdk to obtain the access token from a user. Using asmack, user was logged into the chat. Token was in the form: 226409362971500|3b29bc82baa7901a9baca042.4-72793766|9eb417f06fc376897222938295a0dd0c The code I used was:

XMPPConnection xmpp = new XMPPConnection(config);
SASLAuthentication.registerSASLMechanism("DIGEST-MD5", SASLDigestMD5Mechanism.class);
SASLAuthentication.supportSASLMechanism("DIGEST-MD5", 0);
xmpp.connect();
xmpp.login("226409362971500", "3b29bc82baa7901a9fbaca042.4-72793766|9eb417f06fc376897222938295a0dd0c", "Application");

Now it seems that Facebook has changed the token format. I have tried logging in with the old token, but I always get XMPPException. I've tried logging in with the new access token:

xmpp.login(token, "Application"),
but still no luck. Any idea how to solve this?

Maggie
  • 7,823
  • 7
  • 45
  • 66

1 Answers1

0

After a bit of research (php example on the official FB documentation is really good), I came to a following conclusion:
1. xmpp connection must use ssl
2. in a response, session_key must be replaced with access_token

In short:

ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222);
config.setSASLAuthenticationEnabled(true);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
XMPPConnection xmpp = new XMPPConnection(config);
SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM",SASLXFacebookPlatformMechanism.class);
SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0);
xmpp.connect();
xmpp.login(appSecret, accessToken, "Application");    

SASLXFacebookPlatformMechanism is my class which extends from org.jivesoftware.smack.sasl.SASLMechanism

Maggie
  • 7,823
  • 7
  • 45
  • 66
  • what are the values of appSecret, accessToken: and where i have to use my Uname and Password.. – RajaReddy PolamReddy Jun 14 '12 at 10:42
  • if I remember correctly, you get appSecret when you register your app with facebook. accessToken is obtained via Android Facebook SDK, when user grants permission for your app. – Maggie Jun 19 '12 at 11:32
  • not yet Maggie, help me on this....this is the Question --http://stackoverflow.com/questions/11045241/how-to-create-xmpp-chat-client-for-facebook – RajaReddy PolamReddy Jun 25 '12 at 03:54
  • Thank you for your help, but could you please tell me more about SASLXFacebookPlatformMechanism? Thank you – martinwang1985 Oct 07 '16 at 09:20