使用asmack在Android上使用新的访问令牌的Facebook聊天 [英] facebook chat using asmack on android with the new access token

查看:121
本文介绍了使用asmack在Android上使用新的访问令牌的Facebook聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为Android开发的FB聊天客户端。我一直在使用Facebook的Andr​​oid的SDK,以获得用户的访问令牌。使用asmack,用户登录到聊天。令牌形式:226409362971500 | 3b29bc82baa7901a9baca042.4-72793766 | 9eb417f06fc376897222938295a0dd0c的code我用的是:

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");

现在看来,Facebook已经改变了令牌格式。我曾尝试与旧令牌登录,但我总是得到XMPPException。我试着登录与新的访问令牌:

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(令牌,应用程序)
但仍没有运气。 不知道如何解决这个问题?

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

推荐答案

在一点上的官方FB文档真的很好),我来到了一个如下结论:
 1. XMPP连接必须使用SSL
 在响应2, session_key可以必须替换为 access_token

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

在短期:

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 是我班从 org.jivesoftware.smack.sasl.SASLMechanism

这篇关于使用asmack在Android上使用新的访问令牌的Facebook聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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