Send facebook notification after invitation request

Posted by mahmud ahsan on September 26, 2009 Facebook, PHP

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.

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

Tags: , , ,

Comments (11)

 

  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. mahmud ahsan says:

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

  5. Nikesh says:

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

  6. mahmud ahsan says:

    @Nikesh, currently facebook ban sending notifications from application. So this tutorial will not work now.

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

  8. nikesh says:

    Is any other solution you have.

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

  10. Raj Mohan says:

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

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

Leave a Reply