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;?>"
- Invite Chat from your Canvas Page
- Chat with friends from Canvase Page
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 < 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>
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




