Send facebook notification after invitation request

Posted by mahmud ahsan on September 26, 2009 in Facebook, PHP | 28 Comments

fb_logo 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

  1. notification
  2. invitation

So what is invitation?
Look at these figures:

home_page_invitation

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:

request

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:

Mfs_email

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:home_page_invitation

There will no notification will trigger for invitation/request.
So what is notification?

Notification is like this:

nofitifcation

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)

 

  1. Tonu says:

    WOW! lots of practical fb examples. Sure it will be helpful for FBians.:D
    Awesome post. :D

  2. GirijaSankar says:

    Hi friends if you need any zend mock test go here

    http://orissaost.com/skilltest/

  3. Raj Mohan says:

    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.

  4. Nikesh says:

    Its a gr8 job but its not working fro new api. Will u please check and modify it.

  5. Now facebook has remove this notifications for applications so i think there is no problem in future for notifications.

  6. nikesh says:

    Is any other solution you have.

    • mahmud ahsan says:

      @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.

  7. Raj Mohan says:

    @Mahmud, thanks.. if you dont mind will you provide a sample code.. so that we can utilize in our application…

  8. mahmud ahsan says:

    @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.

  9. Kumaran says:

    Hi Mahmud,

    How to send the “Requests” using facebook apps for my friend ids…Please guide…Thanks

    Best Regards,
    Kumaran,

  10. mahmud ahsan says:

    @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

  11. kumaran says:

    Hi Mahmud,

    Thank you for your reply. Facebook now blocked the below function

    $facebook->api_client->notifications_send($uids, 'some info', 'user_to_user');
    

    What, I need this type of notification or request to our friends. Please guide some alternative solution. Thanks

    Best Regards,
    Kumaran.

  12. mahmud ahsan says:

    @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/

  13. kumaran says:

    Hi Mahmud ahsan,

    How to set multi-select functionality in iframe method.. FBML its working fine… Thanks

    Best Regards,
    Kumaran,

  14. mahmud ahsan says:

    @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.

  15. kumaran says:

    Thanks mahmud,

    How to use javascript in facebook apps…Can you guide me…Please advice…

    I am awaiting for your reply.

  16. mahmud ahsan says:

    @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.

  17. kumaran says:

    Thank you Mahmud….

  18. kumaran says:

    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

  19. mahmud ahsan says:

    @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.

  20. Noirita says:

    hi,

    Thanks for this wonderful article.
    Can you tell me whether i can send message to users after sending application request/invitation.

  21. mahmud ahsan says:

    @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.

  22. Chris says:

    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.

  23. mahmud ahsan says:

    @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/

  24. Newton Curzi says:

    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!

Leave a Reply