【问题标题】:facebook chat using asmack on android with the new access token使用新访问令牌在 android 上使用 asmack 进行 Facebook 聊天
【发布时间】:2011-10-03 10:12:43
【问题描述】:

我有一个为 Android 开发的 FB 聊天客户端。我一直在使用 facebook android-sdk 从用户那里获取访​​问令牌。使用 asmack,用户已登录聊天。令牌的形式是:226409362971500|3b29bc82baa7901a9baca042.4-72793766|9eb417f06fc376897222938295a0dd0c 我使用的代码是:

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。我尝试使用新的访问令牌登录:

xmpp.login(token, "Application"),
但仍然没有运气。 知道如何解决这个问题吗?

【问题讨论】:

    标签: android facebook


    【解决方案1】:

    经过一番研究(official FB documentation上的php例子确实不错),得出以下结论:
    1. xmpp连接必须使用ssl
    2. 在回复中,session_key 必须替换为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 扩展而来

    【讨论】:

    • appSecret、accessToken 的值是什么:以及我必须在哪里使用我的 Uname 和 Password..
    • 如果我没记错的话,当你在 facebook 上注册你的应用程序时,你会得到 appSecret。当用户授予您的应用权限时,通过 Android Facebook SDK 获取 accessToken。
    • 还没有 Maggie,帮我解决这个问题....这是问题 --stackoverflow.com/questions/11045241/…
    • 感谢您的帮助,但您能告诉我更多有关 SASLXFacebookPlatformMechanism 的信息吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    相关资源
    最近更新 更多