Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send facebook chat message via JAXL?
    text
    copied!<p>I am trying to send direct message with JAXL in the name of a user (authenticated application with xmpp_login). In the <a href="https://github.com/abhinavsingh/JAXL/blob/v3.x/examples/xfacebook_platform_client.php" rel="nofollow">jaxl facebook chat example</a> there exist a message echo structure, still it redirects received XMPPStanza to the sender. But trying to generate XMPPStanza to send performs nothing with</p> <pre><code>$client-&gt;send($stanza); </code></pre> <p>here is my XMPPStanza initialization code</p> <pre><code>$stanza = new XMPPMsg(null); $stanza-&gt;from = $client-&gt;full_jid-&gt;to_string(); $stanza-&gt;to = 'example-facebook-id@chat.facebook.com'; $stanza-&gt;type = 'chat'; $stanza-&gt;body = 'test message'; $client-&gt;send($stanza); </code></pre> <p>To sum it up, How can i send message from server in the name of the client via JAXL?</p> <p><strong>EDIT</strong></p> <p>I forgot to mention i am using JAXL v3 and thought about appending full code and system configuration would be more helpful.</p> <pre><code>&lt;?php define('FACEBOOKBOT_PHP', TRUE); // Include XMPP Engine 'JAXL' // Path might be alter in time. // require_once ROOT_DIR.'/JAXL/jaxl.php'; require_once '/var/www/JAXL/jaxl.php'; require_once '/var/www/JAXL/xmpp/xmpp_msg.php'; function sendMessage($client) { // // $stanza = new XMPPMsg(null); // // $stanza-&gt;from = $client-&gt;full_jid-&gt;to_string(); // // $stanza-&gt;to = $to; // // $stanza-&gt;type = 'chat'; // // $stanza-&gt;body = 'test message 1'; // // foreach ($stanza-&gt;childrens as $value) // // { // // $value-&gt;ns = 'jabber:client'; // // } // // $client-&gt;send($stanza); $msg = new XMPPMsg(array('to'=&gt;'example-user-id-and-it-got-to-work-i-checked-on-below-echo-stanza@chat.facebook.com'), 'test message'); $client-&gt;send($msg); _info("test messages sent"); } $user = 'gokhanbarisaker'; // my user id (www.facebook.com/gokhanbarisaker) // $user = $argv[1]; // User name or facebook id $jidSuffix = '@chat.facebook.com'; // Facebook chat account suffix $appKey = 'example-app-key'; // Taken from developer.facebook.com // $appKey = $argv[2]; // Facebook app token $accessToken = 'example-access-token'; // Facebook user token - tried both app token tool on developer.facebook.com and token provided after user login both posses xmpp-login permission // $accessToken = $argv[3]; $client = new JAXL( array( // (required) credentials 'jid' =&gt; $user.$jidSuffix, 'fb_app_key' =&gt; $appKey, 'fb_access_token' =&gt; $accessToken, // force tls (facebook require this now) 'force_tls' =&gt; true, // (required) force facebook oauth 'auth_type' =&gt; 'X-FACEBOOK-PLATFORM', // (optional) //'resource' =&gt; 'resource', 'log_level' =&gt; JAXL_INFO, 'priv_dir' =&gt; '.' )); $client-&gt;add_cb('on_auth_success', function() { global $client; _info("got on_auth_success cb, jid ".$client-&gt;full_jid-&gt;to_string()); $client-&gt;set_status("available!", "dnd", 10); // Here is the part where i tried to send message. In addition, i tried to call this function wherever i can on the code. sendMessage($client); }); $client-&gt;add_cb('on_auth_failure', function($reason) { global $client; $client-&gt;send_end_stream(); _info("got on_auth_failure cb with reason $reason"); }); $client-&gt;add_cb('on_chat_message', function($stanza) { global $client; // echo back incoming message stanza $stanza-&gt;to = $stanza-&gt;from; $stanza-&gt;from = $client-&gt;full_jid-&gt;to_string(); $client-&gt;send($stanza); _info("echo message sent"); sendMessage($client); }); $client-&gt;add_cb('on_disconnect', function() { _info("got on_disconnect cb"); }); $client-&gt;start(); echo "done\n"; ?&gt; </code></pre> <p>System configuration:</p> <ul> <li>Ubuntu 12.04.01 LTS</li> <li>Apache 2.2.22</li> <li>PHP 5.3.10</li> </ul> <p>Terminal command to execute;</p> <ul> <li>> php facebookbot.php</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload