Send facebook notification after invitation request
Posted by mahmud ahsan on September 26, 2009 in
Facebook, PHP | 28 Comments
Sometimes people ask me how to send notification in facebook app after invitation request processed.
This is a very easy solutions. You just need to carefully look the api request and return value. Then you can easily integrate the solution
Here I’m describing what is invitation, what is request and how to send notification after invitation/request successfully processed.
Update 23-04-2010
Facebook closed notification system from application. So sending notification part of this article is now obsolete .
There are many viral features in facebook platform, by using those you can easily inform others about your application. Here I mention 2 of these
- notification
- invitation
So what is invitation?
Look at these figures:
when some one send you any page/application/group invitation or request you’ll see like this figure at the right+top in your facebook homepage.
In application level, how will you integrate this?
According to http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector_(condensed)
if you use this code
<div style="padding: 10px;">
<fb:request-form method="post" action="index.php" content="hey" type="sample" invite="true">
<div class="clearfix" style="padding-bottom: 10px;">
<fb:multi-friend-selector condensed="true" selected_rows="0" style="width: 200px;" />
</div>
<fb:request-form-submit />
</fb:request-form>
</div>
you’ll see the following component in your facebook canvas page:
So users can easily send invitation/request to their friends using this widget in your facebook app.
According to http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector if you use this code
<fb:fbml>
<fb:request-form action="" method="POST" invite="true" type="appname" content="body of the message">
<fb:multi-friend-selector showborder="false" rows="5" exclude_ids="" actiontext="Invite your friends to use this app">
</fb:request-form>
</fb:fbml>
you’ll see the following widget in your facebook canvas page:
So using this widget users can easily send invitation/request to their friends about your app. So what happen when someone send invitation/request using any of these 2 widgets?
The friends who will get invitation/request will see in their home page like below:
There will no notification will trigger for invitation/request.
So what is notification?
Notification is like this:
Now if you want when user will send invitation/request the receiver user will also get notification then how will you implement that?
If you read this 2 pages carefully: http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector_(condensed) or http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector you’ll see:
POST Variables
| Required | Name | Type | Description |
| ids | array | An array of the user IDs chosen by the user. |
What does it mean?
It means, if invitation/request processed successfully facebook will send a variable ids that means receiver friends uids (comma separated list).
So now, if you want after invitation/request processed you’ll additionally send notifications to those users who are invited/requested you can code like this:
<?php if(!empty($_REQUEST['ids'])) {
echo "Your invitation processed successfully!";
include_once "facebook.php";
include_once "config.php";
$uids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : "";
try{
if (!empty($uids))
$facebook->api_client->notifications_send($uids, 'some info', 'user_to_user');
}
catch(Exception $o){
print_r($o);
}
} else { ?>
<fb:fbml>
<fb:request-form action="" method="POST" invite="true" type="appname" content="body of the message">
<fb:multi-friend-selector showborder="false" rows="5" exclude_ids="" actiontext="Invite your friends to use this app">
</fb:request-form>
</fb:fbml>
<?php } ?>
For more info regarding notifications: http://wiki.developers.facebook.com/index.php/Notifications.send
So, the logic is, after processed invitation/request you’ll get user ids, and you’ll send notification to those ids.
Have fun!
Random Posts
If you think this article kicked ass, subscribe to the RSS feed or follow me on Twitter! Share with your friends, or leave a comment below (or better still, do both!)Comments (28)





WOW! lots of practical fb examples. Sure it will be helpful for FBians.:D
Awesome post.
Hi friends if you need any zend mock test go here
http://orissaost.com/skilltest/
WoW.. This is very helpful. thanks man.
I have some question can you pls clarify me pls.
I have a code where I can send request to my friends.
<fb:request-form method="GET" action="application urll" content="My Testing" type="App name" invite="false" content="Hi to all
“>
Using the above code I can able to send request to my friends. Now,
I am having my application user ids in array. Instead of showing my friends inside request form, I want to show my application users. So I can select any one of them from the list and send request to them.
Pls let me know how to do that.
@Raj, please visit http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector here you’ll see exclude_ids. Now listen, you have your application’s user ids, now compare these ids with all your friends ids, and store the unmatched ids and pass them to exclude_ids. You’ll get the solution.
Its a gr8 job but its not working fro new api. Will u please check and modify it.
@Nikesh, currently facebook ban sending notifications from application. So this tutorial will not work now.
Now facebook has remove this notifications for applications so i think there is no problem in future for notifications.
Is any other solution you have.
@Nikesh, yeah you can now send Email from your facebook application. But before that you have to set email domain in the application setting and you have to prompt extended permission to the user, if he accepts then you can mail him.
@Mahmud, thanks.. if you dont mind will you provide a sample code.. so that we can utilize in our application…
@Raj, forget the things now. Because sending notifications from application is now deprecated in facebook. You can send email instead of notification if you want. You can check the following post http://thinkdiff.net/facebook/communicating-with-users-via-email-in-facebook/ for better understanding.
Hi Mahmud,
How to send the “Requests” using facebook apps for my friend ids…Please guide…Thanks
Best Regards,
Kumaran,
@Kumaran, in this article you’ll see the code to send request from your application to your friends. Just remove
try{ if (!empty($uids)) $facebook->api_client->notifications_send($uids, 'some info', 'user_to_user'); } catch(Exception $o){ print_r($o); }this part from my example.
thanks
Hi Mahmud,
Thank you for your reply. Facebook now blocked the below function
What, I need this type of notification or request to our friends. Please guide some alternative solution. Thanks
Best Regards,
Kumaran.
@Kumaran, yeah facebook blocked notification feature for application. As alternative you can request user to give his email address and you can send email to him instead of notification. Checkout this article http://thinkdiff.net/facebook/communicating-with-users-via-email-in-facebook/
Hi Mahmud ahsan,
How to set multi-select functionality in iframe method.. FBML its working fine… Thanks
Best Regards,
Kumaran,
@Kumaran,
you’ve to use server fbml please check this link
http://wiki.developers.facebook.com/index.php/Fb:serverFbml
The fb:serverFbml tag is a very powerful tag for Facebook Connect sites and iframe applications. You use this tag to render FBML tags that otherwise cannot be rendered as XFBML tags (that is, any tags other than the ones that appear in the list above). Typical FBML tags you would wrap within fb:serverFbml are those that require user input, like fb:request-form. The contents of fb:serverFbml are rendered in a Facebook iframe.
Thanks mahmud,
How to use javascript in facebook apps…Can you guide me…Please advice…
I am awaiting for your reply.
@Kumaran,
There are 2 types of javascript for facebook application. One is http://wiki.developers.facebook.com/index.php/FBJS and another is Facebook Javascript Library
http://developers.facebook.com/docs/?u=facebook.jslib
If you want to develop canvas base application you have to use FBJS. Its little modified version of normal javascript. So it would be easy for you to learn if you know javascript.
If you want to develop FBConnect base application, then you could use normal javascript and also javascript framework like JQuery. And Facebook now provide javascript api library using this you can call facebook api directly from javascript.
Thank you Mahmud….
I need one more clarification…I need implement Image coverflow gallery integrate in facebook apps. Please confirm…..
1. Which one is better FBML or Iframe?
2. Coverflow gallery working in javascript. I will change entirely optimize in code in FBJS. Please advice….
I am awaiting for you quick reply. Thanks
Best Regards,
Kumaran
@kumaran
CoverFlow works in a Facebook iFrame App:
http://apps.facebook.com/thaifrau/
Has anybody made a FBML-Version for Facebook Tabs of Coverflow yet?
@Kumaran, it actually depends on you. If you want to use javascript framework like jquery then you’ve to chose iframe. Otherwise you can use fbml canvas.
hi,
Thanks for this wonderful article.
Can you tell me whether i can send message to users after sending application request/invitation.
@Noirita,
Update 23-04-2010
Facebook closed notification system from application. So sending notification part of this article is now obsolete . You can only send email if user provide you email address, you have to ask to get email address from user by calling extended permission.
Hi Mahmud,
In the facebook api wiki, it says that, facebook currently use dashboard.addNews instead of send notification.
Is it alternative solution for this?
What is the different between these two?
Also could you show us an example of how to use addnews funtion?
Please advise.
@Chris, Facebook changing their structure so quickly that if I write a article that become backdated after some months.
Notification from application is closed. You can now only use invitation system and email system and dashboard. Using graph api dashboard working example is different, I yet not write article on it. But you can check this article http://thinkdiff.net/facebook/how-to-use-dashboard-api-of-facebook/
Im happy I located this blog page, I couldnt obtain any information on this matter before. I also run a niche site and if you want to ever interested in a little bit of guest writing for me if possible feel free to let me know, im always look for people to check out my blog page. Please stop by and leave a comment sometime!