Develop customize facebook application for fan page

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

facebook_platformFor many companies or individual, facebook fan page is an integral part of their social media campaign. They want to build up a large follower in their fan page.
Why?

Because, a company want to inform large number of people about their products. An individual want to make large network. As facebook fan page is a part of facebook, so building a large network is quite easy, but for this you have to make your fan page more dynamic, engaging.

In this article I’ll show you how to develop customize facebook application for fan page, that will be more dynamic and interesting for your fans!

fb_page_develop0

Developing fan page application is almost same as developing canvas base application for facebook.  But there are certain limitations in fan page application. I hope you already know how to develop canvas base application, if you don’t know please visit here and learn how to develop canvas application for facebook.

When you’ll setup facebook app, please see the following figures:

fb_page_develop1
* So, you must be set Facebook Pages as checked in the Authentication option.


fb_page_develop2

* And then you’ve to provide a Tab Name and Tab URL, see the following figure. In this case I create tab.php in the app callback directory and set it here.

These twos are the only change when you setup a facebook app for fan page.

now if you want to see how to install an app in facebook fan page, please check this post. Here a procedure is shown to setup facebook app in fan page.

Now I’m describing the technical limitations for fan page app:

1. Fan page app only call to one page  that you provide in the setting like tab.php. So for any other tasks on this page must be done by ajax. So, you can use either Mock Ajax or Normal Ajax.

2. Please look the limitations and policies of Tab Behavior.

3. Remember: in tabbed profile when in fan page, “It doesn’t know who the viewing user is.” And If a viewing user interacts with the tab (like submits a form, takes an action that causes an AJAX load of new content, or follows a relative URL that loads on the tab), that user’s UID is sent to the application

now make a test, in your tab.php file write the following code:

echo '<pre>';
print_r($_SESSION);
echo '</pre>';

you’ll see the following output of your app in fb fan page:

Array
(
 [fb_sig_in_canvas] => 1
 [fb_sig_request_method] => GET
 [fb_sig_is_admin] => 0
 [fb_sig_type] => LOCAL_BUSINESS
 [fb_sig_is_fan] => 0
 [fb_sig_locale] => en_US
 [fb_sig_in_new_facebook] => 1
 [fb_sig_time] => 1252580004.372
 [fb_sig_added] => 0
 [fb_sig_page_id] => XXXXXXXXXX
 [fb_sig_page_added] => 1
 [fb_sig_profile_user] => XXXXXXXXXX
 [fb_sig_profile_id] => XXXXXXXXXXX
 [fb_sig_in_profile_tab] => 1
 [fb_sig_api_key] => XXXXXXXXXXX
 [fb_sig_app_id] => XXXXXXXXXXX
 [fb_sig] => XXXXXXXXXXXXXXXXX
)

look you’ll not get user id or session of the user.

now write this code in you tab.php file

<?php
 if (isset($_REQUEST['name'])){
 echo '<pre>';
 print_r($_REQUEST);
 echo '</pre>';
 return;
 }
?>
<div id="update">
 after form submit</div>
<textarea id="ta"></textarea>
<form action="" id="frm_test" method="post" onsubmit="return false;">
 <input type="text" name="name" size="50" />
 <input type="button" clickrewriteurl='http://callbackurl/tab.php' clickrewriteform='frm_test' clickrewriteid='update' value="submit"/>
</form>

*remember: callbackurl must be replaced by the full callback url that you set when setup the app.

Now check what shows in the page’s tab. You’ll see a form and input field. Now write something and click the submit button. you will see the following output:

Array
(
 [name] => a
 [fb_target_id] => 98736889907
 [post_form_id_source] => AsyncRequest
 [__a] => 1
 [fb_sig_app_id] => xxxxxxxxxxxxxx
 [fb_sig_api_key] => xxxxxxxxxxxxxxxxxxxx
 [fb_sig_page_added] => 1
 [fb_sig_page_id] => xxxxxxxxxxxxxx
 [fb_sig_ext_perms] => auto_publish_recent_activity
 [fb_sig_session_key] => xxxxxxxxxxxxxxxxxxxx
 [fb_sig_user] => xxxxxxxxxxxxx
 [fb_sig_expires] => xxxxxxxxxxxx
 [fb_sig_profile_update_time] => xxxxxxxxxxx
 [fb_sig_added] => 1
 [fb_sig_time] => xxxxxxxxxxxxx
 [fb_sig_in_new_facebook] => 1
 [fb_sig_locale] => en_US
 [fb_sig_is_fan] => 0
 [fb_sig_type] => LOCAL_BUSINESS
 [fb_sig_is_admin] => 1
 [fb_sig_profile] => xxxxxxxxxxxxxxxxxx
 [fb_sig_is_mockajax] => 1
 [fb_sig] => xxxxxxxxxxxxxxxxxxxx
)

look in the output you’ll see [fb_sig_user] and [fb_sig_session_key] of the viewing user. You’ll see the actual output I just replaced them by xxxxxxxxxxxxxx. As after user interaction you’ll get viewing user’s uid and session key, now you can do whatever you want. You can call facebook api or run FQL to get data behalf of user for your app purpose.

In the example i showed using mock ajax, you can also use normal ajax. Now i’m showing how to use normal ajax. Replace all the code of tab.php by the following:

<?php
 if (isset($_REQUEST['name'])){
 echo 'Your name is : ' . $_REQUEST['name'] . '<br />';
 echo 'Your user id is: ' . $_REQUEST['fb_sig_user'];
 }
?>

<script type="text/javascript">
 function sub(){
 var ajax                = new Ajax();
 ajax.responseType       = Ajax.RAW;

 ajax.ondone        = function(data){
 new Dialog(Dialog.DIALOG_POP).showMessage('Status', data, button_confirm = 'Okay');
 }

 ajax.onerror = function(){
 new Dialog(Dialog.DIALOG_POP).showMessage('Error', 'Loading error! Please try again!', button_confirm = 'Okay');
 }

 var params = {'name' : 'mahmud'};
 ajax.post('http://callbackurl/fbapp_test1/tab.php', params);
 return true;
 }
</script>

<form action="" id="frm_test" method="post" onsubmit="return false;">
 <input type="text" name="name" size="50" />
 <input type="button" value="submit 2" onclick="sub();"/>
</form>

now again write someting and click submit. You’ll see a popup dialog and some data where you’ll see user’s id and session key.

*remember: callbackurl must be replaced by the full callback url that you set when setup the app.

You can use html/css/fbml in your app to render in fan page. But always remember, unless user intereact you couldn’t retrieve user’s id. You can also connect your mysql database from php script and can store user’s id for later use, Suppose if you want to develop a quiz game for your fans, and each of the visitor can see the photo and name of users who already played the game. Then you must store the user’s id who played your game already.

So make dynamic app for your fan page, and make your fans more engaging.

Have fun!

Related Posts

Tags: , , , , , , , ,

Comments (22)

 

  1. [...] When will you develop your customize application for facebook page? If you need to use any scripting language like php, asp, jsp. You may need to call some facebook api then you should choose this solution. Click here to see how to develop customize facebook application for fan page [...]

  2. puneet says:

    hi,
    sorry i posted my question with wrong post.

    i want to develop an application for fan page where i will have a form and store the data on the backend.

    when i create the new application in facebook what render method should i choose : fbml or iframe?

    can you provide a link to complete source code for this sample?

    thanks
    puneet

  3. Mahmud Ahsan says:

    its very easy app. you have to pass data by javascript and ajax when user will click submit button. choose fbml.

  4. Chris says:

    Can I do what puneet is asking with an iFrame app? I already have written all the user input error checking in php for my “regular” website.

    I’d like to just import the same form into my facebook app, but I am having tons of problems.

  5. mahmud ahsan says:

    @Chris, in facebook fan page, i’m not sure whether iframe will work or not, please RnD about it.

  6. Scot says:

    Thanks for the info. I have a simple app with a flash banner and a wall below using fb:comments. I am getting an error when I place the app on my fan page. Do i have to create a separate php file for the tab? and if so do I link to the tab.php from my index page?

  7. mahmud ahsan says:

    There are still some limitations in facebook page. So may be fb:comments will not work. You can develop your own commenting system using php/javascript. And create a separate php file like tab.php and set in the developer setting.

  8. Stephen says:

    Thanks, been trying to figure out applications on facebook page tabs for a day now. This solved it.

  9. puneet says:

    hi,

    i have been able to create a custom application for the fan page (thanks a lot for your post). now is it possible to have a web form on the page (eg. tab.php) that allows a user to upload a file in addition to other text data?

    thanks
    pundiv

  10. mahmud ahsan says:

    @Puneet, ofcourse its possible. After file upload and entering text data your form action should be a specif url then you need to redirect the page, or in other way, you can upload file using iframe and form action might be a specific url.

  11. Fadi says:

    i’m trying to add iframe inside facebook page i see it on this page
    http://www.facebook.com/ifan.page.design
    http://www.ifandesign.0fees.net/index.html
    but still can’t figure out how they did it
    ideas anyone?

  12. mahmud ahsan says:

    @Fadi, please try fb:iframe and learn some techinques to work within iframe, i hope you can develop like that using iframe/javascript and ajax.

  13. Arif says:

    Ok. Can you give me any idea how to use the publish_stream the extended permission ?

  14. Eric says:

    Hi,

    I created a canvas page for my application that can be used on fan pages, and thanks to your article it is actually showing up! Thanks. What I would like now is to have a link inside that canvas page that users can click to go to my application. The links I have now all try to go to the application but from within that tab, which doesn’t work. I need to the link to take them to my application like normal. Any ideas?

    Thanks

  15. Eric says:

    Nevermind – I got it to work. Links need to point to a page that requires login, but because I had logic not to require login on a fan page that wasnt happening.

  16. Eric says:

    Other than fb_sig_profile_user, is ther a way to tell who the page admin or owner is? For instance if the page was a business page (Joe’s Plumbing) creatd by Joe, how can I get Joe’s ID?

  17. Eric says:
    Other than fb_sig_profile_user….

    Please check http://wiki.developers.facebook.com/index.php/Pages.isAdmin

    Thanks, I diddnt know about that. But once I determine the ID is not the admin of the page how do I go about getting the admin of that page?

  18. PrellZex says:

    huh. nice style :)

  19. Pankaj says:

    Hi,

    I have created a business page and added application to a tab.

    I want to retrieve the uid of the users who visit the tab. I am using $_POST['fb_sig_profile_user']
    But it give the page id not the uid.

    Actually i want to check whether a visitor has actually voted on a particular issue. For that i have to retrieve uid.

    I used another alternative that is $_REQUEST['fb_sig_user'] but the uid is available after visitor has voted.
    I cannot check whether he has already voted.

    Please help me on this.

    Thanks
    Pankaj

  20. Mahmud Ahsan says:

    @Pankaj, yeah you couldn’t get uid of visitor until they interact with your application. So make a button like Proceed and when user will click it make an ajax call, and you’ll get user id and based on that show him what you want.

Leave a Reply