Android Facebook 聊天示例项目 [英] Android Facebook chat example project

查看:27
本文介绍了Android Facebook 聊天示例项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 此处找到了适用于 iOS 的示例 Facebook 聊天项目.

我还得到了 facebook 聊天文档 这里

同理,

有谁知道 facebook 聊天示例应用程序或在 android 中实现 fb 聊天的方法吗?

Did any one know facebook chat example app or way to implement fb chat in android?

推荐答案

有一个 Android 开源项目可用:Beem Project 和连接 Facebook 聊天,您可以使用以下指南.

There is one Android Open Source Project available : Beem Project and For connecting Facebook chat you can used following guidelines.

在 Android 中实现 Facebook 聊天 API 的步骤:

  1. 首先,我们必须在现有项目中实现 MemorizingTrustManager 库项目.

=> 为此,您必须在现有项目中复制以下三个文件

=> For that you have to copy following three files in existing project

  • MemorizingTrustManager/src/de/duenndns/ssl/MTMDecision.java
  • MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java
  • MemorizingTrustManager/src/de/duenndns/ssl/MemorizingTrustManager.java

=> 并在 values/string.xml

<resources>
    <string name="mtm_accept_cert">Accept Unknown Certificate?</string>
    <string name="mtm_decision_always">Always</string>
    <string name="mtm_decision_once">Once</string>
    <string name="mtm_decision_abort">Abort</string>
    <string name="mtm_notification">Certificate Verification</string>
</resources>

  • 第二步,代替使用SASLAuthentication,例如X-FACEBOOK-PLATFORM,您可以使用以下代码连接Facebook并使用您的登录>Facebook Jabber ID (username@chat.facebook.com)

  • Second step, Instead of using SASLAuthentication such as X-FACEBOOK-PLATFORM, You can used following code to connect with Facebook and login using your Facebook Jabber ID (username@chat.facebook.com)

    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("facebookusername", "****"); // 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("
    
    " + 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();
    }
    }
    

  • 最后,如果您在 LogCat View 中获得您 Facebook 帐户的所有好友列表,那么您可以使用 本教程.

    At last, If you get all the Buddy list of your Facebook account in LogCat View, than you can implement simple Facebook chat using this tutorial.

    这篇关于Android Facebook 聊天示例项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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