Mandalika's scratchpad [ Work blog @Oracle | My Music Compositions ]

Old Posts: 09.04  10.04  11.04  12.04  01.05  02.05  03.05  04.05  05.05  06.05  07.05  08.05  09.05  10.05  11.05  12.05  01.06  02.06  03.06  04.06  05.06  06.06  07.06  08.06  09.06  10.06  11.06  12.06  01.07  02.07  03.07  04.07  05.07  06.07  08.07  09.07  10.07  11.07  12.07  01.08  02.08  03.08  04.08  05.08  06.08  07.08  08.08  09.08  10.08  11.08  12.08  01.09  02.09  03.09  04.09  05.09  06.09  07.09  08.09  09.09  10.09  11.09  12.09  01.10  02.10  03.10  04.10  05.10  06.10  07.10  08.10  09.10  10.10  11.10  12.10  01.11  02.11  03.11  04.11  05.11  07.11  08.11  09.11  10.11  11.11  12.11  01.12  02.12  03.12  04.12  05.12  06.12  07.12  08.12  09.12  10.12  11.12  12.12  01.13  02.13  03.13  04.13  05.13  06.13  07.13  08.13  09.13  10.13  11.13  12.13  01.14  02.14  03.14  04.14  05.14  06.14  07.14  09.14  10.14  11.14  12.14  01.15  02.15  03.15  04.15  06.15  09.15  12.15  01.16  03.16  04.16  05.16  06.16  07.16  08.16  09.16  12.16  01.17  02.17  03.17  04.17  06.17  07.17  08.17  09.17  10.17  12.17  01.18  02.18  03.18  04.18  05.18  06.18  07.18  08.18  09.18  11.18  12.18  01.19  02.19  05.19  06.19  08.19  10.19  11.19  05.20  10.20  11.20  12.20  09.21  11.21  12.22 


Monday, July 27, 2009
 
Instructions to Create a Facebook Application

Here is a quick HOW-To document with step-by-step instructions to create a simple Facebook application.

  1. Create an account with Facebook at facebook.com
  2. To create an application in Facebook, go to Facebook Developers web site
  3. Click on Set Up New Application.
  4. Name the Appliaction and click on save changes.
  5. Enter a brief description for the application.
  6. On the left side of the page click on Canvas.
  7. Fill the application name in Canvas Page URL field.
  8. Fill the Canvas Callback URL field.

    Canvas Callback URL is the address of the website where the appliaction is hosted.
    For example if the appliaction is hosted on a website www.xyz.com, then the Canvas Callback URL address will be http://www.xyz.com/your_application.

  9. Click on save changes.
  10. A summary of the application is shown at this point.
  11. Sample code is shown at the bottom of this page. Click on the sample code.
  12. Download and unzip the tar.gz file.

    In the footprints folder, you will find a sample Facebook application with the file name index.php

  13. Facebook appliaction can be developed in JavaScript, PHP or HTML.

    For more details about the langauges in which the application can be developed, check Facebook Developers web site.

  14. Create your Facebook application and host it on any web site of your choice. Be aware that Facebook does not host the actual application - so you are on your own in finding a hosting site to deploy your Facebook application.

  15. You can test the application from the Canvas Page URL address.

    The url will be in the format http://apps.facebook.com/appliaction_name/


Few Caveats:

If the application is developed in JavaScript, note that all the functions may not work as expected in Facebook. For example, to set the value of 5 to a text box, the following is the code in JavaScript:

var k = 5;
document.getElementById("someid").value = k;


The above code may not work in Facebook application. The following modified code works in Facebook:
var k = 5;
document.getElementById("someid").setValue(k);


To see all the Facebook equivalent functions for the JavaScript functions, check the FBJS wiki page.

If you encounter the error, FBML Error : illegal tag "body" under "fb:canvas", remove the <body> tag from the HTML application. When Facebook parses the appliaction, it addes the <body> tag automatically.

The code shown below is ready to be used as an example Facebook application. This a very basic calculator with limited functionality.

To test how this example code works, visit the following URL:
http://apps.facebook.com/basic_calc

Sample Facebook Application : Simple Calculator


<html>

<head>
<style type = "text/css">
input {
width : 30px;
height: 30px;
font-size: 1.2em;
color: red;
}
</style>

<script language="JavaScript">
var num2 = 0 , num1=0;

function Assign(myvalue)
{
var button_value , Key = 0;
button_value = myvalue.getValue();

switch(button_value)
{
case '+':
case '-':
case '*':
case '/':
case '%':
{
key = button_value;
num1 = num2;
num2 = 0;
break;
}

case '=':
{
if (key == '+')
{
Sum(num1,num2);
}

if (key == '-')
{
Subtraction(num1,num2);
}

if (key == '*')
{
Product(num1,num2);
}

if (key == '/')
{
Reminder(num1,num2);
}

if (key == '%')
{
Modulo(num1,num2);
}
break;
}

case '+/-':
{
num2 = num2 * (-1);
document.getElementById("output").setValue(num2);
break;
}

default:
{
button_value = parseInt(button_value);
combine(button_value);
break;
}
}
}

function combine(input)
{
num2 = (num2 * 10) + input;
document.getElementById("output").setValue(num2);
}

function Cancel()
{
num2 = 0;
num1 = 0;
document.getElementById("output").setValue(num2);
}

function Sum(val1,val2)
{
var result;
result = val1+val2;
document.getElementById("output").setValue(result);
num2 = 0;
num1 = 0;
}

function Subtraction(val1,val2)
{
var result;
result = val1-val2;
document.getElementById("output").setValue(result);
num2 = 0;
num1 = 0;
}

function Product(val1,val2)
{
var result;
result = val1*val2;
document.getElementById("output").setValue(result);
num2 = 0;
num1 = 0;
}

function Reminder(val1,val2)
{
var result;
result = val1/val2;
document.getElementById("output").setValue(result);
num2 = 0;
num1 = 0;
}

function Modulo(val1,val2)
{
var result;
result = val1%val2;
document.getElementById("output").setValue(result);
num2 = 0;
num1 = 0;
}

</script>

<title>Very Basic Calculator</title>
</head>

<form>

<table border="1" bgcolor = "#CDCDCD">

<tr>
<td colspan="6"><input id ="output" type="text" name="result" value="0" style="width: 169px; height: 30px; color:blue;" readonly = "readonly"/></td>
</tr>

<tr>
<td><input type="button" name="one" value="1" onclick = "Assign(this)"/></td>
<td><input type="button" name="two" value="2" onclick = "Assign(this)"/></td>
<td><input type="button" name="three" value="3" onclick = "Assign(this)"/>
<td><input type="button" name="add" value="+" onclick = "Assign(this)"/></td>
<td rowspan="2"><input type="button" name="clear" style = "height : 64px;" value="C" onclick = "Cancel()"/></td>
</tr>

<tr>
<td><input type="button" name="four" value="4" onclick = "Assign(this)"/></td>
<td><input type="button" name="five" value="5" onclick = "Assign(this)"/></td>
<td><input type="button" name="six" value="6" onclick = "Assign(this)"/></td>
<td><input type="button" name="subtract" value="-" onclick = "Assign(this)"/></td>
</tr>

<tr>
<td><input type="button" name="seven" value="7" onclick = "Assign(this)"/></td>
<td><input type="button" name="eight" value="8" onclick = "Assign(this)"/></td>
<td><input type="button" name="nine" value="9" onclick = "Assign(this)"/></td>
<td><input type="button" name="multiply" value="*" onclick = "Assign(this)"/></td>
<td rowspan="2"><input type="button" name="equals" style = "height : 64px;" value="=" onclick = "Assign(this)"/></td>
</tr>

<tr>
<td><input type="button" name="zero" value="0" onclick = "Assign(this)"/></td>
<td><input type="button" name="negative" value="+/-" onclick = "Assign(this)"/></td>
<td><input type="button" name="modulus" value="%" onclick = "Assign(this)"/></td>
<td><input type="button" name="divide" value="/" onclick = "Assign(this)"/></td>
</tr>

</table>

</form>

</html>

________________
Technorati Tags:



Comments:
Thanks for this post..

I am having problems getting my html canvas application to render well in the tab area...I get this error
FBML Error (line 4): illegal tag "body" under "fb:tab-position"
I have removed the body tag like you suggested...but the error still comes up..

Any help would be greatly appreciated..

Thanks

Al
 
Post a Comment



<< Home


2004-2019 

This page is powered by Blogger. Isn't yours?