Facebook Chat Invite API to Increase The Application Users.

March 13th, 2009 by junal Leave a reply »

Over the last few days, we have seen some major changes on Facebook developer platform which will increase the application developers to engage more users with their applications. I will try to write on them one by one in near future whenever I get time. Today, i’m going to discuss “Chat Invite API” with an example and I will also focus on area(s) how we can use this API to get more users attention.

Chat invite API Enables your users to initiate Facebook Chat with their friends from within your applications. Great! Let’s give this responsibility to users to bring their friends in our application.

Three main attributes of this API are..

  • msg (required)
  • condensed
  • exclude_ids

an example could be like the following..

<fb:chat-invite msg="let's play a game!" condensed="false" exclude_ids="1,2,3"/>

2 things are very important here, “msg” that comes in the chat input box when you select an online friend from the list, so be sure that you put something related to your application. Setting up the application URL will be right idea along with some text.

I.e :

 msg ="Come join me! <?=$base_url;?>"

another attribute is “exclude_id”, let’s exclude those who haven’t added this application and idle. So that we will show those users who have not added our application and who are idle. Let’s look at the complete example that does this job for us.

<?php 
include_once("config.php");
$users = $facebook->api_client->fql_query("SELECT uid FROM user WHERE is_app_user = 1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = {$fbuser})");
/*
 * Now, let's make these ids comma seperated (1,2,3)
 */
$arFriends = "";
    // Build an delimited list of users...
    if ($users){
        $arFriends .= $users[0]["uid"];
        for ( $i = 1; $i &lt; count($users); $i++ )    {
            if ( $arFriends != "" )        $arFriends .= ",";
            $arFriends .= $users[$i]["uid"];
        }
    }
?>
//now place this code where you want to show your chat invite box.
<fb:js-string var="chatInvite">  <fb:chat-invite msg="Come join me! <?=$base_url;?>" condensed="true" exclude_ids="<?=$arFriends;?>"/> </fb:js-string>
    <div id="chat_invite_container"></div>
<script> document.getElementById('chat_invite_container').setInnerFBML(chatInvite); </script>

Chat with friends from Canvase Page

Chat with friends from Canvase Page

Thats it! Now, we can allow users to talk to their friends directly from your application.

Reference : http://wiki.developers.facebook.com/index.php/Fb:chat-invite

Advertisement

View Comments

  1. arkofdan says:

    nice
    Can you please put the entire page code for this example please? I really need it

  2. junal says:

    All codes are here, what else you need? just config.php file is missing right. Thats your file that you create with secret key and api key. a config file may look like the follow …
    <?php
    include '../client/facebook.php';

    $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $base_url = 'http://apps.facebook.com/app_name/';
    $callback_url = 'http://clickspan.com/f8apps/directory_name/';

    $facebook = new Facebook($api_key, $secret);
    $fbuser = $facebook->require_login();
    ?>

  3. arkofdan says:

    Thanks man, I will use it ;)

  4. I was really searching for this code. It really helpful for me and other application users. Thanks for sharring

  5. Rahul says:

    Your “for” statement appears to have 4 conditions instead of 3. Perhaps the formatting went wrong??

  6. Rahul says:

    Also it looks like facebook updated something because when i tried it this is what i got

    Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Parser error: unexpected ')' at position 92.' in /home/<site>/facebookapi_php5_restlib.php:1648 Stack trace: #0 /home/<site>/includes/facebookapi_php5_restlib.php(267): FacebookRestClient->call_method('facebook.fql.qu…', Array) #1 /home/n<site>/index.php(14): FacebookRestClient->fql_query('SELECT uid FROM…') #2 {main} thrown in /home/<site>/includes/facebookapi_php5_restlib.php on line 1648

  7. Rahul says:

    Your “for” statement appears to have 4 conditions instead of 3. Perhaps the formatting went wrong??

  8. Rahul says:

    Also it looks like facebook updated something because when i tried it this is what i got

    Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Parser error: unexpected ')' at position 92.' in /home/<site>/facebookapi_php5_restlib.php:1648 Stack trace: #0 /home/<site>/includes/facebookapi_php5_restlib.php(267): FacebookRestClient->call_method('facebook.fql.qu…', Array) #1 /home/n<site>/index.php(14): FacebookRestClient->fql_query('SELECT uid FROM…') #2 {main} thrown in /home/<site>/includes/facebookapi_php5_restlib.php on line 1648

  9. Sudipta says:

    1) Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Parser error: unexpected ')' at position 92.' in /home/<site>/facebookapi_php5_restlib.php:1648 Stack trace: #0 /home/<site>/includes/facebookapi_php5_restlib.php(267): FacebookRestClient->call_method('facebook.fql.qu…', Array) #1 /home/n<site>/index.php(14): FacebookRestClient->fql_query('SELECT uid FROM…') #2 {main} thrown in /home/<site>/includes/facebookapi_php5_restlib.php on line 1648

    2)chatInvite is not defined javascript error

  10. helena01 says:

    don't works; have some problem in this line

    for ( $i = 1; $i < count($users); $i++ ) {

    Parse error: syntax error, unexpected ';', expecting ')'

  11. mbt outlet says:

    Well , the view of the passage is totally correct ,your details is really reasonable and you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!
    http://www.sin-game.com

Leave a Reply

blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes