Facebook chat connect with X-FACEBOOK-PLATFORM using Jaxl 2.0

Facebook chat provides two authentication mechanisms for authenticating chat client users. DIGEST-MD5 require chat client users to enter their username and password, while X-FACEBOOK-PLATFORM can be used to provide better user experience by using simple Facebook Platform authentication. In this blog post, I will demonstrate how to use Jaxl library for X-FACEBOOK-PLATFORM authentication.

Echobot using X-FACEBOOK-PLATFORM
Setup Jaxl library on your system and edit packaged sample echobot application with facebook user account details. Alternately you can also specify connecting user details inside jaxl.ini configuration file.

        $jaxl = new JAXL(array(
                'user'=>'fbUsername',
                'pass'=>'', // Not required, we will use user session key instead
                'host'=>'chat.facebook.com',
                'domain'=>'chat.facebook.com'
        ));

Add callback for hook jaxl_get_facebook_key:

JAXLPlugin::add('jaxl_get_facebook_key', array($echobot, 'getFacebookKey'));

Complete getFacebookKey method inside echobot application, which should return back following key information:

function getFacebookKey() {
                        return array(
                                '', // Your application secret key
                                '', // Your application api key
                                '' // Connecting user session key
                        );
                }

Update doAuth method to use X-FACEBOOK-PLATFORM auth mechanism:

                function doAuth($mechanism) {
                        global $jaxl;
                        $jaxl->auth("X-FACEBOOK-PLATFORM");
                }

Finally, run echobot from command line:

[email protected]:/usr/share/php/jaxl/app/echobot# jaxl echobot.php
[1942] 2010-08-08 05:35:10 - Socket opened to the jabber host chat.facebook.com:5222 ...
[1942] 2010-08-08 05:35:11 - Performing Auth type: X-FACEBOOK-PLATFORM
[1942] 2010-08-08 05:35:26 - Auth completed...
  • Elas

    Congratulation on the new library… Fb auth example works just as expected 😀

  • samual

    Hi Abhinav,

    I am using JAXL library jaxl-2.0 ,jaxl-2.0.0.tar.gz (downloaded from http://code.google.com/p/jaxl/downloads/list ) for one of my facebook connect applications to use facebook chat, I want to use X-FACEBOOK-PLATFORM authentication I followed all the above steps, my questions are
    (1)is it possible to use email in place of user name because as much i know it is not possible to get username of each facebook user
    (2)I added jaxl_get_facebook_key hook but it never get called.
    (3)I ran echobot,php from command line and for testing provided my facebook session_key and now it hangs at Performing Auth type: X-FACEBOOK-PLATFORM when i looked into log I found following
    [[XMPPSend]] 185

    X-FACEBOOK-PLATFORMDIGEST-MD5
    [[XMPPSend]] 0

    As I can see from here that nothing goes from client to facebok server then i changed startAuth function(not sure doing right)to include the case for X-FACEBOOK-PLATFORM as
    case ‘X-FACEBOOK-PLATFORM’:
    $xml = ”;
    break;
    and now again ran echobot.php, this time result Unable to complete SASL Auth, see logs for detail… Jaxl Shutting down … and in log
    dXNlcm5hbWU9InN1ZGhhbnNodS5zaXJvaGlhIixyZXNwb25zZT0i….

    pls help me out

  • samual

    sorry for posting again same post..

    If I use ‘digest-md5’ with facebook password and user name it works fine but as I dont want to let the user re-input their facebook name and password, how could I get their password to use digest-md5 authentication

  • Kindly use development branch code for using X-FACEBOOK-PLATFORM authentication. http://github.com/abhinavsingh/JAXL

    No, I don’t think email can be used to login into facebook chat, user must have chosen a username. Correct me if I am wrong.

    While using X-FACEBOOK-PLATFORM approach, you need to provide 3 information when jaxl_get_facebook_key is called i.e. api_secret, api_key, and user_session_key.

    You need to obtain user_session_key with extended xmpp_login permissions. http://developers.facebook.com/docs/chat

    No you cannot obtain a user password from user_session_key for use with digest-md5. If you want to skip re-input of username/password, X-FACEBOOK-PLATFORM is the only solution.

    Do let me know how it goes.

  • samual

    Hi abhinav,
    thnx for quick reply but at http://www.aim.com you can see they just need facebook login (no username)..can u suggest how do they are implementing this

  • Simple enough, use facebook user id instead of username. E.g. http://www.facebook.com/profile.php?id=544265614 leads to http://www.facebook.com/abhinavsingh, hence “-544265614” can be used as my username instead of “abhinavsingh”.

    You get this user id during facebook oauth process, hence never a password must be required for chat connect. Hope it helps.

    #Jaxl 2.0.3 is out!, Includes working #Bosh #Chat example, X-FACEBOOK-PLATFORM auth support. View Changelog http://bit.ly/9YQvXL for details

  • Pingback: Releasing Jaxl 2.0 – Object oriented XMPP framework in PHP | Abhi's Weblog()

  • Pingback: Jaxl 2.0 Core classes, available methods and directory structure | Abhi's Weblog()

  • Samual

    Hi Abhinav,

    Thankyou so much for your help. I have achieved communcication between my server and fb chat server using X-facebook platform. I want to create a web based chat client for fb chat.

    I have two doubts:-

    1.) Do we have to run jaxl.php for each user seperately or just running it once for all users is fine?

    2). How do I communicate between the browser and fb chat server for frequent updates?
    I can’t do ajax calls as jaxl.php runs continously w/o giving any response. I know it writes log files but how do I send messages to browser…

    Any pointers would be really appreciated. I have been working on this for more than 10 days 🙁

  • a) If you are running a bosh application, jaxl.php will be invoked every time an ajax is sent from the browser. Jaxl don’t have any one instance architecture for bosh applications, you can’t just run jaxl.php once for all users.

    b) I already answered to your query here before: http://bit.ly/dCYslf on how to communicate with facebook chat servers using browser applications. Try one of the following standalone bosh connection managers:

    JabberHTTPBind http://blog.jwchat.org/jhb/
    Punjab http://code.stanziq.com/punjab/
    Araneo http://blog.bluendo.com/ff/bosh-connection-manager-update
    rhb http://rubyforge.org/projects/rhb/

    Let me know how it goes. 🙂

  • Samual

    Thanks for the prompt replies but I am still stuck like anything, rather more confused…
    Why do I need a Bosh Connection manager?

    Will simple ajax calls to jaxl.php not suffice?

    Please tell me the major steps I need to do in order to integrate facebook chat on my website using php….

    Can I please have your cell no./chat id so we can have a direct talk?

  • Hi Samual,

    Kindly contact me on my email ([email protected]) and we can discuss more about your application needs and workflow.

  • samual

    hi abhinav,

    Thnx for your so much support…I have successfully implemented jaxl library for xmpp chat , now working on emoctions in chat message any suggestion for this??

  • samual

    sorry emoticons

  • Ajay

    Hi Abhinav,

    I am trying to understand and use facebook chat using jaxl.

    When I run the JAXL, the app hangs after Performing Auth type: X-FACEBOOK-PLATFORM.

    The logs show that the app receives the challenge from the server but it does not send a response.

    I am using the latest stable version. Can you please help?

    Regards,
    Ajay

    • Hi Ajay, Sorry was out on vacation n just back. Can you paste jaxl.log content on pastebin or other online tools so that i can debug in detail. Also from my experience, post Auth, bind/session steps can take time for facebook.com/jabber.org jabber servers.

  • Ajay

    Hi Abhinav,

    I have tried to fix the issue and have found a fix. The echobot now works with facebook after a few changes in JAXLXml.parse method, though I am not sure if it will break something.

    Maybe it has to do with the version of php (5.1.6) on my servers. You seem to be using a newer version.

    I am sending the changes through email, so that you can review them.

    Regards,
    Ajay

  • Thanks Ajay. I have received your fix via email and I shall review the same with different versions of PHP on my system and push appropriate fix asap.

    I currently use: PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) on my box which has not given any problem till date.

  • Paul

    I’m wondering if you have any example code for getting roster/presence from Facebook using a session key. I want to do this from in the context of the web, and not the command line.

    I’ve tried to follow your example for the command line, but I was unable to get it to run.

    An example would be immeasurably helpful.

    Thanks

  • Emmanuel

    hey! Am building a website and i want my vistors to access their facebook chat rooms without having to navigate away from my website. The problem is that i just cant figure out how to exactly do this. Can some one pliz pliz help…i badly need help

  • Shaun
  • Mear diesel

    Hello Abhinav, I have seen that you have updated and committed some new codes into the github. I have installed and do the tutorials but i couldnt make the facebook echo bot run. Could you please, upload a sample “echobot with facebook” ? I have tried also http://abhinavsingh.com/blog/2010/02/writing-your-first-facebook-chat-bot-in-php-using-jaxl-library/ But even i am sure that the username (both used username and facebookid) is correct, it stopped in step : Attempting DIGEST-MD5 Authentication…

    Waiting for a reply from you. Thanks for your efforts!

    • Did you try /app/echobot.php example from github repository. Also how are you planning to run your echobot, from command line or browser?

  • met

    hello, what is the “connecting user session key” ? shouldnt it be gathered by us ? Or it is a variable that is provided by facebook?

    • Hi Met,

      After successful facebook connect operation (oauth), fb returns a session key in response. You need to use the same session key while connecting that user to facebook chat.

  • Yaniv

    Hello Abhinav.

    I’ve got a php wrapper for the JAXL lib, so I can use it through a browser call… However, we’ve been getting lots of requests stuck on G or W mode on apache, which causes lots of hangs on our server… Have you ever encountered it? seems like the request don’t time out correctly, or not shutting down properly…

    • Hi Yaniv,

      How many concurrent request does you application end up making to the web server?
      Depending upon your application needs you might want to play with apache max child/client and related configurations.
      Would appreciate if you can share your php wrapper so that i can test the things myself.
      If you don’t want to open it up, simply email me if you like to.

  • Hi Abhinav,

    I have an app that uses your latest JAXL to send a chat message for FB users (FB users will see a popup chat dialog when any kind of messges arrive).

    Problem is this function worked well until a test today. Not sure any changes in FB or your lib?

    Also, I checked file /var/log/jaxl.log.. look like correct.

    So strange for this.

    Please help me.

    Regards,
    Luong Le

  • Hi Abhinav,

    I am using PHP 5.2 and latest of JAXL. See my log after sending chat message: http://12g.me/log.txt

    Any suggestions?

    Thanks,
    Luong Le

  • Brad

    Is X-FACEBOOK-PLATFORM authentication still working for anyone who has created a new app id/key in the last few days? I’m receiving an authentication failure over XMPP.

  • Brad

    Nevermind that last comment. Totally works. Thanks for the reference implementation! Now I can proceed with a proper auth mechanism.

  • Jason Serafin

    Get [[XMPP]] Unable to open socket to the jabber host.

    Code:

    ‘appId’,
    ‘secret’ => ‘secret’,
    ‘cookie’ => true, // enable optional cookie support
    ));

    $session = $facebook->getSession();

    $me = null;
    // Session based API call.
    if ($session) {
    try {
    $uid = $facebook->getUser();
    $me = $facebook->api(‘/me’);
    } catch (FacebookApiException $e) {
    error_log($e);
    }
    }

    include_once(‘jaxl/core/jaxl.class.php’);

    $jaxl = new JAXL( array(
    ‘user’=>$me[‘id’],
    ‘pass’=>”, // Not required, we will use user session key instead
    ‘host’=>’chat.facebook.com’,
    ‘logLevel’=>’5’,
    ‘mode’=>’cli’,
    ‘domain’=>’chat.facebook.com’));

    $jaxl->requires(array(
    ‘JAXL0115’, // Entity Capabilities
    ‘JAXL0092’, // Software Version
    ‘JAXL0199’, // XMPP Ping
    ‘JAXL0203’, // Delayed Delivery
    ‘JAXL0202’ // Entity Time
    ));

    function postAuth($payload, $jaxl) {
    $jaxl->sendMessage(‘[email protected]’, ‘Hello World’);
    $jaxl->shutdown();
    }

    function doAuth($mechanism) {
    global $jaxl;
    $jaxl->auth(“X-FACEBOOK-PLATFORM”);
    }

    function getFacebookKey(){
    return array(
    ‘secret’,
    ‘appId’,
    $session[‘session_key’]
    );
    }

    // Register callback on required hooks
    $jaxl->addPlugin(‘jaxl_get_auth_mech’, ‘doAuth’);
    $jaxl->addPlugin(‘jaxl_get_facebook_key’, ‘getFacebookKey’);
    $jaxl->addPlugin(‘jaxl_post_auth’, ‘postAuth’);
    // Fire start Jaxl core
    $jaxl->startCore(“stream”);

    ?>

    • Hi Jason,

      You pasted the code but told me little about your problem? Is X-FACEBOOK-PLATFORM auth working fine for you?

  • I am also getting

    [[XMPP]] Unable to open socket to the jabber host

    What can be the possible reason behind this?

  • Update: Hosting had blocked it, had to get it activated.

  • Vlad

    Guys,
    I have a big problem, very very frustrating.

    I keep getting this error when I try to run the example from above:
    Fatal error: Call to undefined function jaxl_require() in /usr/local/lib/php/jaxl/core/jaxl.class.php on line 41

    I installed the Jaxl on my linux dedicated several times… but I stilll get this error.

    Can anyone help?

    Thanks,
    Vlad

  • Vlad

    EDIT: IT seems that downloading the latest pack from the GIT fixed the problem.
    I am now getting : [[XMPP]] Unable to open socket to the jabber host

    • Hi Vlad,

      That simply means Jaxl was unable to socket to $jaxl->host
      Kindly telnet $jaxl->host 5222 from your box to check if the host is accessible from your box.

  • Maize

    Hi Abhinav,

    i have read through your posts about xmpp and connection to facebook with big interest.

    Unfortunately i always get the

    error. The new Jaxl-Version you just uploaded and the one u already linked in the comments here do not work for me.

    They also donot the “build.sh” anymore which i would use to resetup my JAXL completely.

    Is there any way to debug the Facebook denial more or debug why my jaxl isn’t running on newest version? I do “jaxl myfile.php” and nothing happens. Not even an error.

    Thanks in advance.

    Greets
    Maize

  • Ahmed Aly

    Hi..
    Thanks for your contribution..
    But I still need to know.. does the x-facebook authentication mechanism really work?

    Waiting for your answer urgently, and thanks.

  • JMP

    Hi,

    I am using the latest branch from http://github.com/abhinavsingh/JAXL … but I have a problem.

    First of all there is no doAuth function in the echobot file, so how do I update it? Also, do I need to add the doAuth as a plugin?

    All I get at the moment when trying is:

    [1:97963:0] 2011-03-20 12:50:55 – [[XMPP]]
    Socket opened to the jabber host chat.facebook.com:5222 …

    And it stays stuck on that.

    I am using $arg[1] for the user, which equals my user id as: “-10299288”

    The session is $arg[2] which is my session_key Facebook returns when allowing the app with xmmp_login permissions.

    Any help?

    • Hi JMP,

      There is a 'authType'=>'PLAIN' parameter passed to JAXL constructor. Which automatically chooses PLAIN authentication mechanism if available.
      You should change that to X-FACEBOOK-PLATFORM and then also implement required callback using JAXLPlugin::add('jaxl_get_facebook_key', array($echobot, 'getFacebookKey')); .

      Also i recommend users to download and use v 2.1.2-rc1 from google code download tab.

  • JMP

    Thanks Abhinav,

    One more question. The above works, but it returns:

    [[XMPPGet]] Unable to complete SASL Auth, see logs for detail…

    I’ve added a break point and a log to the code, and Facebook is returning “not-authorized”.

    So, my question/s are.

    1) How should the username be formatted?
    2) Is the secret the app secret or the session secret?
    3) Is the session the session_key or the access_token (I know some people use them interchangeably).

    I am running from my computer, but I have set up my IP with Facebook as the url for the application. That shouldnt make a difference though right?

    Any response to the above questions, or advice, would be appreciated. I do plan on documenting this in a video for users at a later date.

    Thanks.

  • Construct0r

    HI Abhinav!

    I downloaded newest version of jaxl. 2.1.2. Do i need to install it, or just place in folder and include in my php files?

    • Main feature improvement of 2.1.2 is that there is no build.sh, it simply follows download/extract/include usage policy.

  • Ahmed Aly

    Hi and thanks for your reply..
    This is all I get when I try to use the library:
    [[JAXL]] No callbacks for shutdown [1:30205:0] 2011-03-20 21:15:48 – [[JAXL]] Calling JAXL0115 method getCaps [1:30205:0] 2011-03-20 21:15:48 – [[JAXLPlugin]] Executing hook jaxl_get_id for uid 1 [1:30205:0] 2011-03-20 21:15:48 – [[JAXL]] Shutting down …

    it seems like it does not connect.. so I need to know what should I call to connect to the server?

  • Construct0r

    Abhinav,
    hi, i have a problem i can’t solve for hours…
    there is a problem in connection. Here is log:
    Socket opened to the jabber host chat.facebook.com:5222 …
    Performing Auth type: X-FACEBOOK-PLATFORM
    and then, fail:
    [1:3937:0] 2011-03-21 04:14:03 – [[XMPPGet]] 4096

    [1:3937:0] 2011-03-21 04:14:03 – [[XMPPGet]] Unable to complete SASL Auth, see logs for detail…

    i tested everything. I think it’s problem in $session[‘session_key’], because it’s empty.
    I have $session array, and it have sig, access_token, expire and uid, but there is no session_key.
    There is xmpp_login in permission list. I downloaded newest facebook.php (facebook api).
    I use edited version of your test app (sendMessage.php), I edited it for use with facebook.

    If you know what can be problem, please help!

    Thank you.

  • Ahmed Aly

    Hi @Construct0r
    Can you share that code you have pls?

  • Donny

    Hi Abhinav, great work on this frame work thanks so much. Do you know if its still possible to see what facebook users are active over XMPP. When I fetch the roster it appears they payload contains no online presence data? Best Regards, Donny

  • Construct0r

    Ahmed, ofcourse. Look into it, and if you find error, please let me know.

    [code]
    #####################aaa#####################
    $session = $facebook->getSession();

    $jaxl = new JAXL(array(
    ‘user’=>$me[‘id’],
    ‘pass’=>”,
    ‘host’=>’chat.facebook.com’,
    ‘domain’=>’chat.facebook.com’,
    ‘authType’=>’X-FACEBOOK-PLATFORM’,
    ‘mode’=>’cli’,
    ‘logLevel’=>4
    ));

    echo “$session[session_key]“;
    print_r($session);
    function getFacebookKey() {
    return array(
    $f_setAppSecret, // Your application secret key
    $f_setAppApi, // Your application api key
    $session[‘session_key’] // Connecting user session key
    );
    }

    // Post successful auth send desired message
    function postAuth($payload, $jaxl) {
    $jaxl->sendMessage(‘[email protected]’, ‘Hello World’);

    $jaxl->shutdown();
    }

    // Register callback on required hooks

    $jaxl->addPlugin(‘jaxl_get_facebook_key’, ‘getFacebookKey’);
    $jaxl->addPlugin(‘jaxl_post_auth’, ‘postAuth’);
    // Fire start Jaxl core
    $jaxl->startCore(“stream”);
    #############################################
    [/code]

    above this code is part with includes i need, code for permission request for application, app connection with facebook, etc.
    Theoretically, this code should work, but i really don’t know why. I think it is because there is no session_key in $session array (which you get with $session = $facebook->getSession();

    Maybe facebook disabled it for some reason? Has anybody here application which works with chat at the moment? is it about me or facebook?

    And, if i remove ‘mode’=>’cli’, from code, there is no logs or anything. Just like script doesnt execute…
    Thank you!

  • Matt

    Can you tell me how I can send a message in facebook chat to another user?

    This is my code:
    function postAuth($payload, $jaxl) {

    $jaxl->sendMessage(‘[email protected]’, ‘hi’);
    $jaxl->shutdown();
    }

    but it doesn’t work.
    Do you have any idea on what I’m doing wrong?

    LOG:
    2011-03-21 13:08:24 – [[XMPP]]
    Socket opened to the jabber host chat.facebook.com:5222 …

    [1:16900:0] 2011-03-21 13:08:24 – [[XMPPSend]] Performing Auth type: X-FACEBOOK-PLATFORM

    [1:16900:1] 2011-03-21 13:08:25 – [[XMPPGet]] Auth completed…

    [1:16900:1] 2011-03-21 13:08:25 – [[JAXL]] Shutting down …

    • Hi Matt, Does your user facebook session key have xmpp_login permissions??

  • Matt

    Ok I figured my problem posted above, but no I don’t know how to get a list of all online users.

    Can anybody help on how to do this?

    Thanks

  • Ahmed Aly

    I am trying the old code now, but its telling me: missing action.

    I am not sure what does it mean?

  • Construct0r

    Hi Abhinav,
    I made it! It connects and sends message correct! Thank you for awesome work.

    Now, I just need help about how to get list of online users. I have $session array and session_key. Please help:)

    Thank you, again!

  • Matt

    yes it has xmpp_login permissions.
    i managed to get a list of all users
    but i only need one of online users, how can i do that?

  • Ahmed Aly

    @Matt
    Can you pls share the full page, and which jaxl version you are using?

    Thank you so much in advance.

  • Ahmed Aly

    @Construct0r
    can you pls tell me which version of jaxl you are using? 🙁
    I am stuck.

  • Construct0r

    newest one, 2.1.2..:)

  • Ahmed Aly

    @Construct0r
    Thank you so much.

    I replaced some of my code with yours, and started responding, but it still does not really work..
    here is what I got:
    [[JAXL]] OpenSSL extension is loaded. [1:31923:0] 2011-03-21 18:35:54 – [[XMPP]] Unable to open socket to the jabber host chat.facebook.com:5222 …

    should I try it with another IP address?

  • Skypeep
  • El33

    Abhinav, hi.
    I succefully made application which connects to facebook and sends chat message to choosen friend. It works great, but there is a problem. Most of users (90%) said that their antivirus reports application as virus (xmpp virus)!? what!? Why is that? Application does not have anything illegal or special, just simple option to send message.

    • Anti virus doesn’t know anything about the library or sendMessage() method. Anti-virus is most probably detecting the incoming message as virus because of content or links inside it. I am not sure, but no reason why Jaxl library will have to do anything with such messages…..

  • El33

    btw. I forgot to mention, it’s a facebook application (iframe on apps.facebook.com/…).

  • Skypeep

    contat me guys for code. i made it working…..

  • El33

    But, which incoming message? there is no incoming message, only send…

  • El33

    Ok, solved it, it wasn’t about jaxl. It’s because of loading external pages in iframe

  • snider

    @Skypeep You can share the Code with me?

  • Hafiz

    Hi Abhinav…

    I like your code here, but I think you must create new post to explain Step By Step about JAXL + X-FACEBOOK-PLATFORM. Many user want to know it, but I think something missing (explanation) here. And this code too :
    #############################################
    $session = $facebook->getSession();

    $jaxl = new JAXL(array(
    ‘user’=>$me[‘id’],
    ‘pass’=>”,
    ‘host’=>’chat.facebook.com’,
    ‘domain’=>’chat.facebook.com’,
    ‘authType’=>’X-FACEBOOK-PLATFORM’,
    ‘mode’=>’cli’,
    ‘logLevel’=>4
    ));

    echo “$session[session_key]”;
    print_r($session);
    function getFacebookKey() {
    return array(
    $f_setAppSecret, // Your application secret key
    $f_setAppApi, // Your application api key
    $session[‘session_key’] // Connecting user session key
    );
    }

    // Post successful auth send desired message
    function postAuth($payload, $jaxl) {
    $jaxl->sendMessage(‘[email protected]’, ‘Hello World’);

    $jaxl->shutdown();
    }

    // Register callback on required hooks

    $jaxl->addPlugin(‘jaxl_get_facebook_key’, ‘getFacebookKey’);
    $jaxl->addPlugin(‘jaxl_post_auth’, ‘postAuth’);
    // Fire start Jaxl core
    $jaxl->startCore(“stream”);
    #############################################

    I test the fresh code jaxl/app/sendMessage.php and just change Username & Password at that files, but still got error :

    Warning: touch() [function.touch]: Unable to create file /var/log/jaxl.log because Permission denied…

    Fatal error: Uncaught exception ‘JAXLException’ with message ‘Log file /var/log/jaxl.log doesn’t exists’

  • Ahmed Aly

    Hi..
    I have the code working successfully with x-facebook authentication, but I can’t get a list of online users?

    Did anyone get it successfully?

  • Hafiz

    Hi Ahmed, can you share your experience here? I got nothing 🙁

    Hope this post not called spam here :

    Hi Abhinav, already test your v2.1.2… Is this just can run on localhost? Can’t run on web hosting? I’m using PHP5 too and test your code more than 5 hours just now and nothing I got for possible run FB Chat… 🙁

    I think your guide not complete or not update. Hope you can make a new post and telling how to & step by step about new version…

    I already test your old version too, and seriously I got nothing here… And I don’t know this is the truth code can use FB Chat or not… Still try and try but now very stuck just focus on your code…

  • Don

    Hi Abhinav,

    I’ve already contacted you on Facebook Private message, but hope you don’t mind that I post my issue here too… 🙂

    My PHP Version: 5.2.9
    My System: CENTOS 5.5 i686 virtuozzo on cpanel

    I’m using the latest JAXL downloaded from github.com

    My problem: I’ve got this while outputting $jaxl:

    [xml] => XML Object
    (
    [valid] =>
    )

    Seems the XML object is still empty (I’ve heard that someone had this problem too and you’ve made a patch for it to work on CENTOS too, but despite of that update i’ve still got empty XML object)…

    I appreciate your work on JAXL, its really a nice tool!

    You can contact me on facebook (if you see my messages) or post an asnwer here.

    Thanks in advance!
    Greetz
    Don

  • Ahmed Aly

    @Hafiz..
    contact me and I will help you for sure.

  • tb

    Bhai abhinav, yeh FB Viral Chat app install kaise kartey hai, hume thoda help kijiye.

  • Markuz

    @Ahmed Aly
    can you helpme too?

  • Matt

    Don’t help those people please, they want to create an app that spamms all facebook friends with an advertising message once they allow the app!

  • Martin

    This is too short and 100% impossible for a newbie to figure out.

    Next time Abhinav, make the FULL tutorial and post it, or don’t post it at all.

    This does nothing…

    Good luck!

  • mrbnp

    exactly! This is like 10% of the whole app.

  • constantin

    this is a grate app but didn`t really managed to connect using the 2.1.2 version. congratulations to abhinav!!

  • El33

    Abhinav…
    I can get list of online friends with getRoster…but it’s kinda slow-because it returns list of all friends (first those who are online, and then offline users). Is there any way to make it return only online users? I saw it uses $payload = ”; … any modification?

    • Hi El33, This is something that you need to handle inside your app itself. You have $jaxl->roster which have a list of ur buddy and whether they r online or offline information. In case they r online, it also provide you with resource info associated with the user.

  • Andrew

    Hi All!
    I’ve successfully got auth, but cant send message to another user. Which format for sending message i should use???
    1. $jaxl->sendMessage([email protected], ‘Hello World’);
    2. $jaxl->sendMessage([email protected], ‘Hello World’);
    3. something else
    Suggest the solution, please.

  • Andrew

    Thanks for All ))) The answer is 2) 🙂

  • Shaun

    Hi, I’m attempting to integrate web-based facebook chat into my application and I was having trouble connecting to chat.facebook.com
    (
    [[XMPP]] Unable to open socket to the jabber host
    )

    I read many of the above comments and decided to check to see if port 5222 was blocked on my server…it was! 🙁

    I’m guessing there’s no way around this, so I’m wondering if you guys who are successfully up and running would have any good suggestions on web hosts that don’t block 5222? (And under $10…I don’t need VPS or anything fancy like that)

    I hope you don’t mind the mildly unrelated question, but jaxl will be extremely useful to my applications and I’d love to get it up and running!

    Thanks in advance!

  • I was getting function jaxl_require not defined errors too, I downloaded the latest build from code.google.com and I am no longer getting this error but I am getting deprecated errors:

    ( ! ) Deprecated: Call-time pass-by-reference has been deprecated in C:wampwwwJAXLxmppxmpp.class.php on line 300
    Call Stack
    # Time Memory Function Location
    1 0.0008 696584 {main}( ) ..preFetchXMPP.php:0
    2 0.0028 1037464 require_once( ‘C:wampwwwJAXLcorejaxl.class.php’ ) ..preFetchXMPP.php:19
    3 0.0029 1039400 jaxl_require( ) ..jaxl.class.php:108

  • Pingback: facebook chat bot()

  • stella

    Hi Abhinav,

    I have a question, not about jaxl API, but about how the authentication is done in detail (the message flow between the xmpp client and facebook chat server).

    I guess the authentication start with a msg from my app to facebook:
    “”;

    What is the ClientID? How to get the client ID? is it my facebook userid or something else?

    Thanks a lot for your kind help!

  • alex

    Abhinav Singh, thanks for this awesome work.

    For those who get the error “Unable to complete SASL Auth” it might be related to the old Facebook authentication. Now OAuth2.0 returns the access_token but X-FACEBOOK-PLATFORM needs a session_key.

    The solution is in the access_token. An access_token is form as follow:
    AAAAAAA|BBBBBBBB|CCCCCCCC

    which is:
    AppID|Session_key|Some_sig

    To use X-FACEBOOK-PLATFORM, you can extract the session_key from the
    access_token and authenticate the user.

    Cheers

  • Cadell

    hello, firstly excellent work however long it took me to finally get it running, secondly i am trying to run this code remotely on a free web host by simply running the script by browsing to the page. this produces no errors but it doesn’t say it has succeeded either. also my jaxl log is empty. is something wrong? and alex i wish i saw your post about an hour ago.

  • Cadell

    i’ve been working with the prefetchxmpp.php file if that helps.

  • Cadell

    NEVER MIND I GOT IT I’M SO HAPPY FINALLY!!!!!!!!!!!!

    if anyone wants to know how to get this working on a regular webhost with prefetch.xmpp.php instead of the console let me know, free of charge ofcourse unlike some other people i’ve seen.

  • stella

    Hi,

    I am writing a web app, where I want the user to be able to:
    1) log in to Facebook
    2) have FB chat function (load facebook friends list, updated with friends online status information, be able to send/receive chat msg)

    My first attempt was using XHR to call an auth.php to do the x-facebook-platform authentication, resource binding, etc via a socket. It was successful. However,I would like to keep the socket alive and let other php script (triggered by other XHR when the user wants to send a msg) to use that socket. I am stuck there. I found no solution to let several php share one socket.

    Therefore, I am investigating how to use JAXL libary. Does jaxl library server my purpose? Does it allow my webpage communicate with facebook chat server directly, to do the authentication, sending/receiving msg, presence update?

    Thanks for your kind help!

  • Dev

    Hi Cadell

    I would like to know how to work the script from browser. Can you please help.

    Thanks.

  • Mohit

    Hi Abhniav

    Thanks for such a great library.

    I am able to authenticate user with x-facebook-platform and send a message to other users. But I am facing issue while I add plugin for get message :

    $jaxl->addPlugin(‘jaxl_get_message’, array($echobot, ‘getMessage’));

    if I use $jaxl->shutdown() at the end, getMessage stops working.
    I understand that $jaxl must be running, but if I do not write $jaxl->shutdown(), my script hangs and doesnot allow me to surf other pages on my site.

    I am running script from browser.

    How can I handle such situation..?

    Please help me on this issue.

  • Cadell

    Dev i am making the tutorial at the moment i just need to make this work ona remote server instead of my local apache one. does anyone know a free webhost that supports stream_socket or an alternative to stream_socket?

  • Mark

    I am able to auth successfully. and also able to send message in postAuth.

    My query is : Can we use “sendMessage” function in postAuth method only ?

    How can we use “sendMessage” at our desired action.?

  • To dev and all others concerned in authenticating with facebook chat from a web server instead of the console, i have written a tutorial on how to alter the prefetchXMPP.php to authenticate with facebook. here is the link http://cadellchristo.tk/?p=6

  • Mark

    Hi Abhinav

    How can I set the user to offline with JAXL.?

  • Berk

    Hi Abhinav,
    I am implementing a facebook chat,
    Do I really need bosh chat. I have problems using bosh server.

    What does boshhost, host and domain represents in jaxl settings?

  • Hi Abhinav
    i have a quick question. what function needs to be complete before i can populate an online and offline users list. at the moment i am calling back after “jaxl_post_roster_update” but this appears to cut off the end response of the roster list on a list of 500 people (the data sent doesn’t even have a closing tag as if the last block is missing). is it meant to take about 40 secs?

  • and another question do i have to re-authenticate everytime i want to call a new function?

  • Evgeny

    Well, but how to send messages to Facebook friends?..

  • Kavita

    hi abhinav ,can you please tell me how can we implement xmpp chat into USSD?

  • Ivan

    Hello, Abhinav.

    I hope, its suitable place to ask question about your great library)

    Recently, facebook updated theirs authentication mechanism, and now library is unable to sucesfully finish authentification, using ‘session_key’. Developers have to use ‘auth_token’ instead.

    My question is, do you planning to make any updates of library? Or may do you know somebody, who already dealt with same problem, and have solution for it?


    With best regards, Ivan

    • Hi Ivan, Indeed your are the first one to report this via a blog comment or via group post. Few developers already reported about this via chat to me, probably about a week ago. I guess that was when facebook changed their authentication mechanism requirements. I plan to update the library and come out with various patches submitted by various other developers. However u can until then simply go and use the library by what you have found out as the code breaking change. I will mostly update the library by monday with new changes required for successful facebook auth.

  • Ivan

    Hi, Abhinav.

    It is a very good news!

    Maybe this will be usefull for you, facebook have updated SASL authentication sample in dev dosc here(now its on PHP): http://developers.facebook.com/docs/chat/

    However, there is one bug in that sample code, they have forgot opener tag ” in the string $SESSION_XML.


    Thank you, Ivan

  • George Rubin

    JAXL Patch:

    xmpp.auth.php line 62, change:

    list($secret, $decoded[‘api_key’], $decoded[‘access_token’]) = JAXLPlugin::execute(‘jaxl_get_facebook_key’, false, $jaxl);

    $decoded[‘call_id’] = time();
    $decoded[‘v’] = ‘1.0’;

    $base_string = ”;
    foreach(array(‘api_key’, ‘call_id’, ‘method’, ‘nonce’, ‘access_token’, ‘v’) as $key) {
    if(isset($decoded[$key])) {
    $response[$key] = $decoded[$key];
    $base_string .= $key.’=’.$decoded[$key];
    }
    }

    Enjoy!

  • Ivan

    Thanks, George.

    It works!

  • Jason

    @George Rubin, @Ivan & @Abhinav,

    I am completely new to XMPP/BOSH/Chat, so bear with me.

    I am trying to use PHP to talk with Facebook Chat API and this library seemed promising.

    Due to the architecture of my clients mobile platform, I can’t use Javascript or the command line. So I need to use PHP’s GET & POST var’s.

    I am confused about two things:

    1) how to establish a connection using Jaxl to Facebook Chat using OAuth/X-FACEBOOK-PLATFORM SASL authentication mechanism.
    2) once I’ve established a connection, and send a test message to a Facebook Chat user, how can I get Jaxl to display the chat response?

    I hope you can help shed some light on this for me!

    Cheers, Jason.

  • Bhoopesh

    Hi Abhinav,

    I am trying to implement Facebook chat on website using Jaxl.

    i have configured jaxl.ini, echobot.php as per instructions given in http://abhinavsingh.com/blog/2010/08/facebook-chat-connect-with-x-facebook-platform-using-jaxl-2-0/

    But i am getting a Fatal Error as : Call to undefined function jaxl_require() in /home/helloh5/public_html/dev/fbchat2/core/jaxl.class.php on line 41

    i was not able to find function jaxl_require() in complete Jaxl Project.

    Please help me.

  • Lina Clark

    Hi abhinav,
    I am trying to implement XMPP client for X-facebook-platform where i need not give my login credentials. My appId and access token can fulfill the purpose. I am able to connect successfully but afterwards i don’t know how to login to facebook chat so that i can fetch the friend list of the user.
    Can ya help..

    Thanks
    Lina

  • Ajay krish

    http://bitly.com/x15uAS?X331111
    i get this spam every time i chat
    how to get rid of it?

  • Eyasu

    I had to update xmpp.auth.php in jaxl/xmpp with the following changes.

    Replace session_key with access_token

    The API parameters have changed with OAuth 2.0

  • Djay

    Hi,

    Can we connect to Facebook XMPP with BOSH mode ?

    Thanks
    Djay

    • yes but you will have to either use a self-hosted bosh server or a publicly hosted bosh server somewhere to get this done

  • Announcing Jaxl v3.x – asynchronous, non-blocking I/O, event based PHP client/server library – http://abhinavsingh.com/blog/2012/07/announcing-jaxl-v3-x-asynchronous-non-blocking-io-event-based-php-clientserver-library/

  • Pingback: How to perform X-FACEBOOK-PLATFORM and Google Talk X-OAUTH2 XMPP authentication with PHP Jaxl library | Abhi's Weblog()