How to send Facebook application request

In this tutorial we are going to show You how to write functions that are going to communicate with Facebook through API to send facebook application request. First function is going to display invite friends dialog and the second one is going to display dialog which is used to publish scores to players timeline.

Facebook API is distributed as Javascript code. The first thing is to include this code in Your page.

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js">

Next You need to initialize API by calling FB.init method:

<script type="text/javascript">
    FB.init({
		appId:'xxxxxxxxxxxxxxx', 	// Your Application ID
		cookie:true, 				// Enabling cookie support
       	status:true, 				// Fetch fresh status
		xfbml:true 					// Parse XFBML tags
	});
</script>

API is initialized and ready to use. Our next function is going do display invite friends dialog

<script type="text/javascript">
function inviteFriends() {
	FB.ui({ method: 'apprequests',
		message: 'Take the challenge in ITC click challenge app.'});
}
</script>

Next function is going to display a dialog which is used to publish game results to players wall.

<script type="text/javascript">
function publishScore(clicksNum) {
	msg = 'My score on ITC click challenge app is ' + clicksNum + ' clicks!';

	FB.ui({ method: 'feed',
	name: 'ITC Click Challenge',
	caption: 'Come on and beat it!',
	description: msg});
}
</script>

You can use those functions like in the following examples in Your application code.

<a href="javascript: inviteFriends();">Invite friends</a>
<a href="javascript: publishScore (1200);">Invite friends</a>

Our sample game code the ‘ITC Click Challenge’ where we use those functions can be downloaded from here.

2 Responses to "How to send Facebook application request"

  1. Красимир Кривчев says:

    For first time, i see tutorial about programing, with so sexy intro. Magdalena, when i looking you, i forget coding ;-))

    Reply
  2. Praveen Mylavarapu says:

    Thank you for your great tutorial but this is not working for me. So I downloaded your sample game which is above and hosted it. Even that is not working for me. Please help me to send invites of my app. apps.facebook.com/praveengame .

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>