title: How to create XMPP chat client for facebook?
body: <p>I'm creating XMPP client for <strong>FACEBOOK</strong>. i did this for gmail, now i have to create  same for FaceBook. i googled a lot for this got some code, still i'm getting this type of errors <code>Not connected to server</code> and <code>service-unavailable(503)</code></p>
  
  <p>here i'm sharing the code what i did.</p>
  
  <pre><code>public class ClientJabberActivity extends Activity {
  
  ArrayList&lt;String&gt; m_discussionThread;
  ArrayAdapter&lt;String&gt; m_discussionThreadAdapter;
  XMPPConnection m_connection;
  private Handler m_handler;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      m_handler = new Handler();
  
      try {
          initConnection();
      } catch (XMPPException e) {
          e.printStackTrace();
      }
  
      final EditText recipient = (EditText) this.findViewById(R.id.recipient);
      final EditText message = (EditText) this.findViewById(R.id.message);
      ListView list = (ListView) this.findViewById(R.id.thread);
  
      m_discussionThread = new ArrayList&lt;String&gt;();
      m_discussionThreadAdapter = new ArrayAdapter&lt;String&gt;(this,
              R.layout.multi_line_list_item, m_discussionThread);
      list.setAdapter(m_discussionThreadAdapter);
  
      Button send = (Button) this.findViewById(R.id.send);
      send.setOnClickListener(new View.OnClickListener() {
          public void onClick(View view) {
  
              String to = recipient.getText().toString();
              String text = message.getText().toString();
  
              Message msg = new Message(to, Message.Type.chat);
              msg.setBody(text);
              m_connection.sendPacket(msg);
              m_discussionThread.add(" Me  : ");
              m_discussionThread.add(text);
              m_discussionThreadAdapter.notifyDataSetChanged();
          }
      });
  }
  
  private void initConnection() throws XMPPException {
  
      ConnectionConfiguration config = new ConnectionConfiguration(
              "chat.facebook.com", 5222, "chat.facebook.com");
      config.setSASLAuthenticationEnabled(true);
      m_connection = new XMPPConnection(config);
      try {
          SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM",
                  SASLXFacebookPlatformMechanism.class);
          SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0);
          m_connection.connect();          
          m_connection.login(apiKey + "|" + sessionKey, sessionSecret, "Application");
      } catch (XMPPException e) {
          m_connection.disconnect();
          e.printStackTrace();
      }
  
      Presence presence = new Presence(Presence.Type.available);
      m_connection.sendPacket(presence);
  
      PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
  
      m_connection.addPacketListener(new PacketListener() {
          public void processPacket(Packet packet) {
              Message message = (Message) packet;
              if (message.getBody() != null) {
                  String fromName = StringUtils.parseBareAddress(message
                          .getFrom());
                  m_discussionThread.add(fromName + ":");
                  m_discussionThread.add(message.getBody());
  
                  m_handler.post(new Runnable() {
                      public void run() {
                          m_discussionThreadAdapter.notifyDataSetChanged();
                      }
                  });
              }
          }
      }, filter);
  
      ChatManager chatmanager = m_connection.getChatManager();
      chatmanager.addChatListener(new ChatManagerListener() {
          public void chatCreated(final Chat chat,
                  final boolean createdLocally) {
              chat.addMessageListener(new MessageListener() {
                  public void processMessage(Chat chat, Message message) {
                      System.out.println("Received message: "
                              + (message != null ? message.getBody() : "NULL"));
                      Log.i("CHAT USER",
                              "Received message is: " + message.getBody());
                  }
              });
          }
      });
  }
   }
  </code></pre>
  
  <p>and this class <a href="https://stackoverflow.com/a/5843759/964741">SASLXFacebookPlatformMechanism</a></p>
  
  <p>How can i login like this <code>xmpp.login(apiKey + "|" + sessionKey, sessionSecret, "Application");</code> i know how to get acessToken, Application Key for facebook. i don't know about sessionKey, sessionSecret how to get those values and how to solve this problem.</p>
  
  <p>If i use <code>xmpp.login(apiKey, accessToken, "Application");</code> i am getting this error --IllegalArgumentException: API key or session key is not present</p>
  
  <p><strong>EDIT:</strong> Finally i got solution from Amal solution : <code>xmpp.login(apiKey, accessToken, "Application");</code></p>