Archive for the ‘Facebook’ Category

facebook application development part one

7

Dec
06

Well it’s been a while since I promised a Facebook tutorial and finally it is here. Well Part One at least. :-)
In this first part I will go through the process of creating a very simple Facebook application focusing on the adding the application and the embedded profile application itself.
I will be using PHP5 throughout the course of this tutorial in conjunction with the Facebook PHP5 Client Library.

download the facebook client library 

tutorial

Once you have download the Facebook Client Library and extracted the contents you will be presented with a facebook-platform folder and within this a client folder (The PHP 5 client and the code base we will be using for this tutorial), footprints (A Facebook demo application) and a php4client folder (The PHP 4 client). 

To start off with we will create a folder called “tutorial” within the root “facebook-platform” folder.

Next we need to create to PHP files; index.php and config.inc.php. The contents of these files are displayed below: 

index.php

The index.php provides the foundation for the entire application. This is where the initial add page is created along with the embedded application.

 
  1. First of all we need to include the facebook client library and the config.inc.php.
// the facebook client library
include_once ‘../client/facebook.php’;

// this defines some of your basic setup
include_once ‘config.inc.php’;

  1. Next we instantiate an instance of the facebook class and force the user authentication before logging in.
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();
  1. Now we create an add application screen to be initially displayed when a user clicks to see your applications hompage. This code includes two simple facebook variables to display the users facebook username and to add the facebook add url for the application.
<div style="padding: 10px;background-color:#FFFFFF;">
  <h2 style="font-family:arial;font-size:14px;">Hi <fb:name firstnameonly="true" uid="<?=$user?>" useyou="false"/>!</h2><br/>
    
    <div style="width:255px;float:left;border-right:1px solid #FFFFFF;background-color:#333333;height:100px;padding: 10px;"><a href="http://www.andrewsellick.com"><img src="http://news.andrewsellick.com/facebook-platform/asellick/images/logo.gif" alt="AndrewSellick.com" title="AndrewSellick.com" style="border:0px solid #FFFFFF;" /></a></div>
    
    <div style="width:330px;float:left;background-color:#333333;height:70px;color:#FFFFFF;padding: 25px 10px 25px 10px;font-family:arial;">
    
        <p style="margin:0px 0px 8px 0px;">Welcome to the AndrewSellick.com Facebook App.  If you want to know all the latest news on AndrewSellick.com feel free to add this application to your profile.</p>
        <p style="margin:0px 0px 0px 0px;"> <a style="color:#FFFFFF;text-decoration:underline;" href="<?= $facebook->get_add_url() ?>">Add AndrewSellick.com</a>.   &nbsp;&nbsp;&nbsp; Enjoy…</p>
    
    </div>
    
    <div style="clear: both;"/>
    
  <p><a href="<?= $facebook->get_add_url() ?>">Put AndrewSellick.com in your profile</a>, if you haven’t already!</p>
   
  <div style="clear: both;"/>
</div>
  1. Finally we create the FBML code. This is the code that will be displayed for the embedded application. The code is very simple and is added using a Facebook Client API call $facebook->api_client->profile_setFBML(); This set the FBML when the Facebook application is added.
<?php

    // Create the FBML code for the embeded application
    $fbml .= ‘<div style="width:100%;">’;
    $fbml .= ‘<div style="width:133px;float:left;border-right:1px solid #FFFFFF;background-color:#333333;height:100px;padding: 10px;"><a href="http://www.andrewsellick.com"><img src="http://news.andrewsellick.com/facebook-platform/asellick/images/logo-small.gif" alt="AndrewSellick.com" title="AndrewSellick.com" style="border:0px solid #FFFFFF;" /></a></div>’;

    $fbml .= ‘<div style="width:200px;float:left;background-color:#333333;height:100px;color:#FFFFFF;padding: 10px;font-family:arial;font-size:12px;">Welcome to the AndrewSellick.com Facebook App.  This application provides you with the latest news from AndrewSellick.com. <br /><br /><a style="color:#FFFFFF;text-decoration:underline;" href="http://www.andrewsellick.com">Visit AndrewSellick.com</a></div>’;

    $fbml .= ‘<div style="clear: both;"/>’;

    $fbml .= ‘<div style="width:371px; border:1px solid #333333;background-image:url(http://www.andrewsellick.com/wp-content/themes/unsleepable/images/sub-nav-bg.gif);background-repeat:repeat-x;position:top left;" id="andrewsellick-feed">’;
    $fbml .= ‘<div style="padding:10px;font-family:verdana;font-size:11px;">’;
        
            $fbml .= ‘<p style="margin:0px 0px 8px 0px;color:#666666;"><a style="color:#DA1074;" href="http://www.andrewsellick.com/">Link One</a> – </p>’;
            
            $fbml .= ‘<p style="margin:0px 0px 8px 0px;color:#666666;"><a style="color:#DA1074;" href="http://www.andrewsellick.com/">Link Two</a> – </p>’;
            
            $fbml .= ‘<p style="margin:0px 0px 8px 0px;color:#666666;"><a style="color:#DA1074;" href="http://www.andrewsellick.com/">Link Three</a> – </p>’;
            
            $fbml .= ‘<p style="margin:0px 0px 8px 0px;color:#666666;"><a style="color:#DA1074;" href="http://www.andrewsellick.com/">Link Four</a> – </p>’;
            
            $fbml .= ‘<p style="margin:0px 0px 8px 0px;color:#666666;"><a style="color:#DA1074;" href="http://www.andrewsellick.com/">Link Five</a> – </p>’;
        
    $fbml .= ‘</div>’;
$fbml .= ‘</div>’;

$fbml .= ‘<div style="background-color:#333333;width:373px;font-family:arial;font-size:12px;">’;
    $fbml .= ‘<p style="padding:10px;margin:0px;"><a style="color:#FFFFFF;" href="’.$facebook->get_add_url().’">Put AndrewSellick.com in your profile</a></p>’;
$fbml .= ‘</div>’;

$fbml .= ‘</div>’;

$facebook->api_client->profile_setFBML($fbml, $user);

?>

config.inc.php 

In this tutorial the config.inc.php will remain very simple and only includes two variables for the Facebook API key and a secret key. These are provided when you create your Facebook application in within the Facebook developer area (Detailed later in this tutorial).

$api_key = ‘INSERT THE API KEY HERE’;
$secret  = ‘INSERT THE SECRET HERE’;

download the tutorial code 

Download the facebook application development tutorial code.

integrating the application with facebook 

To actually add the application to Facebook you will need to go through the follwing procedures.

 
  1. Upload the code within the facebook-platform folder to a PHP5 hosting environment.
  2. Log in to Facebook and navigate to the Facebook developer page (http://www.facebook.com/developers/).
  3. Click the “Set Up a New Application” button on the top right of the page.
  4. Insert your desired application name and submit.
  5. On setting up the application you will presented with an overview which displays basic application information including the API key and Secret required in your config.inc.php. Copy these two keys and insert them in your config file and then re-upload the file.
  6. Next on the overview page click to edit your newly created application.
  7. Next we need to insert the application details as follows:
    • The Callback Url – Add the URL to the root of the tutorial application folder you created and uploaded as above. I.E. http://www.yourdomain.com/facebook-platfom/tutorial/
    • The Canvas Page URL – Add your desired canvas page URL. This has to be unique to Facebook, although there is automatic validation to prompt you if it is not, so choose wisely. An example could be “andrewsellicktutorial” making the URL http://apps.facebook.com/andrewsellicktutorial/
    • Select the option to allow your application be added on Facebook.
    • The select users to be able to add your application on all pages.
    • Add your Canvas Page URL to the Side Nav URL. I.e. http://apps.facebook.com/andrewsellicktutorial/
    • Now save the application and that’s it.
 

To test it out navigate to the Canvas Page URL in your browser. You should then be able to go through the process of adding the application and finally seeing it displayed on your profile page.

notes 

This is a very basic example so I wouldn’t recommend users start to advertise their applications off the back of this tutorial. There will be more tutorials to come introducing more features and discussions on the Facebook Cache, its potential pitfalls and how to overcome them.

Feel free to play with the code and adapt it for your requirements and let me know how you get on…

I hope this has helped. :-)

Facebook Invite Friends Code

11

Nov
26

Facebook Invite CodeIn light of my inpending article on how to create a simple Facebook application I thought I would point you all to a link which you may find helpful now if you already have some experience in developing facebook applications, or if not, you will 100% find it useful after my next article.

The code basically provides the "invite your friends" functionality to your application.  It was developed by dustinfisher.com and is a really handy piece of code when it comes to devloping Facebook applications as it can greatly increase the amount of people who add your application. The more the better huh :-)

Anyway have a look for yourself at the Facebook Invite Friends Code or simply download the Facebook Invite Friends Code.

AndrewSellick.com on Facebook…

2

Nov
22

I was recently asked to research the possibility of developing Facebook applications and potential timescales in which they could be developed, so I decided the only way I could properly answer that question was to develop a simple application myself to get to grips with what’s required.

AndrewSellick.com Facebook ApplicationTherefore I give you the AndrewSellick .com Facebook app. Woooo ;-)

It’s a simple application literally just providing news directly from my web site feed into Facebook (Well I did say it was simple). However I thought it was as good a place as any to get started.

Have a look for yourself at the AndrewSellick.com Advert Facebook application.

I am planning on releasing a tutorial over the next few days documenting how to create a simple app such as this so check back soon if you’re interested in Facebook. Better still add the app to your Facebook profile and wait for the article to come through the feed ;-)

Anyway if anybody experiences any difficulties or has any comments please leave them at the bottom of this post.