0
votes

I am developing a simple chat client for FB. I have progressed to a state where now i have the access_token of the user who had logged in to my chat with "xmpp_login" and "offline_access" scope. Am able to successfully connect to chat.facebook.com and also login using api_key and the access_token. There is no problem in the SASL Authentication.

Now when i try to send a message using, chat.sendMessage(String) or chat.sendMessage(Message), the smack debugger shows the message has been sent. But on my facebook website, I dont see that message sent to that person.

hellokVfox0

This is the output from Smack debugger Sent column. Is there anything wrong with the from address? or with this message structure? Am stuck at this point because i dont know how to debug this issue.

Any advice, suggestions or solutions are most welcome.

This is the code snippet i am using,

        ConnectionConfiguration config = new                 ConnectionConfiguration("chat.facebook.com",5222);//ProxyInfo.forHttpProxy(soc.getHostName(),8080, null, null));
    config.setSASLAuthenticationEnabled(true);
    XMPPConnection connection = new XMPPConnection(config);
    XMPPConnection.DEBUG_ENABLED = true;
    SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM", SASLXFBAuthentication.class);
    SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0);
    connection.connect();
    String apiKey ="282973731790200";
    String accessToken ="My access token with xmpp_login and offline_access scope";
        connection.login(apiKey, accessToken);
    Chat newchat = connection.getChatManager().createChat("[email protected]", new MessageListener() {


        public void processMessage(Chat chat, Message message) {
            // Print out any messages we get back to standard out.
            System.out.println("Received message: " + message);
        }
    });
    Message msg = new Message();
    msg.addBody("English", text);
    msg.addSubject("English", "Test");
    msg.setType(Type.chat);
   // connection.sendPacket(msg);
    newchat.sendMessage(msg);   

Thanks and Regards, Karthik

1
The message in smack debugger was, <message id="7t1b1-4" to="[email protected]" from="[email protected]/Smack_a12852bb_4BEE613208288" type="chat"><body>hello</body><thread>kVfox0</thread></message>Karthik
When you say you don't see the message, does the OTHER person see the message?Igy
Nope..the other person also does not see the message and there is no exception as well. Should i encode the message or it can be a plain string like chat.sendMessage("hello"). Should i post my code here?Karthik
Can someone advice me what needs to be done or if i am missing something?Karthik

1 Answers

2
votes

I have fixed this issue.

The to address to whom the message was intended should also be JID format. To obtain this, we need to make use of Roaster Class of smack and get all the connections or friends in facebook. Doing so helped me to send a message to the intended JID.

Thanks, Karthik