Wow! Teenage girls are tech savvy.

A tech savvy teenager, yesterday.
One of the sites I have developed for a customer is designed for Prom Dresses, called Prom Palace.

I was just looking through the logs, as we have been doing some facebook advertising of late (very useful, you can target much better than using google ads), and I was amazed to see the following browser stats:

Chrome: 42%
IE: 36% (9: 14%, 8: 17% 7-: 5%)
Firefox: 12%
Safari: 9%
Others: Negligible.

Total hits: 150,000

Compare that to the main bridal site I do, Glamourous Gowns, and while they have many more hits (800,000+) they are less tech savvy:

IE: 54% (9: 15%, 8: 26%, 7-: 13%)
Chrome: 18%
Firefox: 15%
Safari: 10%
Android: 1%
Others: Negligible

This highlights a number of things:

1. Never guess what your punters are using. Always check the stats.
2. Chrome is now a heavyweight browser.
3. Some 25% of my punters won’t be able to cope with CSS3 and HTML5 etc.
4. Either, I shouldn’t spend any time developing mobile versions of the sites, OR I should do them a lot better. At the moment if you access via a smartphone you default to a very basic menu system and an ugly looking display screen. I am investigating JQuery mobile at the moment, so significant improvements may be a few lines of code away…

Have other people experienced similar trends in browser usage? If so, what industry are they aimed at etc?

Boosting Facebook Fan Page Traffic with Tags

Up until a few weeks ago, I thought that tagging on Facebook involved only photographs. I had read various complaints about people’s privacy being invaded blah blah blah, but hadn’t paid much attention because I don’t really use Facebook for photos.

However, one day a client asked me how they could get links to appear in their wall posts like such and such did. I had no idea what they were talking about until they showed me, and then I was stumped, as I had no idea how it was done. Rather than bore you with the details of what I did next, I will cut to the chase.

This is a tag.

Facebook Fanpage Tags - Part 1

Note from the tag, that I have referred to the facebook fanpage in my wall post, and if hovered over, the link produces the bubble as shown.

Now, if you follow that link, you get to the Facebook fanpage. What you don’t get on that fanpage, is a copy of the post on our wall. However, if the facebook fanpage allowed posts from other people that is exactly what would happen. So using a tag, you not only get a nice engaging link on your own fanpage, but you can also get the same post appearing on the tagged fanpage. This post will be read by all the fans of that page.

Obviously, you have to be careful. You don’t want to make a load of spam posts which will annoy the fanpage owners you are tagging. Do that and you will get blocked. Also, they will think that you are an idiot and if you are a customer of their’s they will think twice about sending any business your way in future.

So, the way to use this facility is to write a genuinely engaging wall post that refers to the fanpage you are tagging.

This is how to do it.

The first thing to do is log on using an id that has admin rights to the fan page you want to post on.

Once you have done that, you need to find the link on the right of the screen that says something like “Use facebook as [My fan page]“.

Facebook Fanpage Tags - Part 2

Click that link, and you are now posting as the fan page. In this case, I am using the fan page of a client of mine; Glamourous Gowns.

Oh, another thing you should do, is to like the fan page you are about to tag. This is a common courtesy, and if you don’t want to like the fan page you are trying to tag, why on Earth are you tagging them?

Ok, so you are now using Facebook as your fanpage. The next thing you want to do is make a wall post. I know that Glamourous Gowns recently added the new wedding dress ranges from Mori Lee and Forever Yours. So it would be nice to make a wall post mentioning this, and linking to the Glamourous Gowns website. I also know that Mori Lee and Forever Yours both have fan pages on Facebook. So the post will want to tag them.

So I start typing my message, and when I get to the point where I want to add a tag for Mori Lee, I type the @ character, and start typing Mori Lee.

Facebook Fanpage Tags - Part 3

Facebook detects that I am trying to type a tag, and presents a dropdown of available tags, based on what I have typed already. I want the MORI LEE BRIDAL GOWN tag, so I select that and continue with the message.

Facebook Fanpage Tags - Part 4

As you can see, Facebook highlights the tag and lets you carry on typing.

Once the message is complete, I post it, and see what has happened?

Facebook Fanpage Tags - Part 5

Yes, I now have nice tags on my post, pointing to the Mori Lee and Facebook fanpages.

The best is yet to come though…

Facebook Fanpage Tags - Part 6

As you can see here, the Mori Lee Bridal Gown fanpage is configured to show my post! My wall post is now being potentially seen by all fans of this page.

And thats all there is to it. A few things to remember:

1. Tagging on a fanpage only works if you are using facebook as the fanpage.
2. Like the fanpage you tag.
3. Only use tags for legitimate posts.
4. Not every fanpage will show your post, however the tag will always appear on your own fanpage.

Using Action Links to enhance a user’s post.

Somebody asked about action links yesterday. Up until now I had never heard of them, but they are quite cute. Basically they allow you to add a link to the bottom of a user’s post.

See it in action.

If you run this test app, and use it to post a comment to your wall, you will notice the “Sweet FA” link, which links you to facebookanswers.co.uk.

The full source code for that app is shown in this article:

Publishing to a User’s Wall

The important bit of code is here:

$attachment = array
 (
 'access_token'=>$facebook->getAccessToken(),
 'message' => 'I\'ve been testing my IQ!',
 'name' => 'IC-YOUR-IQ',
 'caption' => 'This is my result:',
 'link' => 'http://apps.facebook.com/icyouriq/',
 'actions' => array('name'=>'Sweet FA','link'=>'http://www.facebookanswers.co.uk'),
 'description' => $cmsg,
 'picture' => 'http://www.facebookanswers.co.uk/img/misc/iq.jpg'
 );

The key bit is the “actions” section.

Uploading pictures using the PHP SDK

NB: this is in response to a question posed on our Facebook Fan Page, and is a work in progress. If you have any comments or see mistakes, don’t be shy. The code here is rough and ready and liable to revision. So don’t be surprised if you find errors.

The application can be run here: Photo Love

If you run the application, you are presented with a list of albums, and you select one. A picture is then uploaded into that album.

There are two programs:

index.php

<?php

// This should point to wherever you have your php facebook api.
require_once ("../src/3.11/facebook.php");
// id of any associated fan page.
$cfanpageid = "142393235804950";
// URL of the above
$cfanpage = "http://www.facebook.com/pages/Face-Answers/142393235804950";
// Application ID
$cappid = "xxxxxxxxxxxxxxx";
// Application Secret
$cappsecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $cappid,
'secret' => $cappsecret,
'cookie' => true,
'domain' => 'facebookanswers.co.uk'
));

$user = $facebook->getUser();

// NOTE!!!! Make sure you use the permissions shown below.

if (!$user) {
    $url = $facebook->getLoginUrl(array('scope'=> 'read_stream, publish_stream, photo_upload, user_photos, user_photo_video_tags','redirect_uri'=>'http://apps.facebook.com/photolove/'));
    echo "<p>Redirecting to perm request...</p>";
    echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
} else {

  try {
         $facebook->setFileUploadSupport(true);
        $likes = $facebook->api('me/likes');
        $fa_fbfriends = $facebook->api('me/friends');
        $fa_fbalbums = $facebook->api('me/albums/');
        $fa_fbme = $facebook->api('me');
        $fa_fbname = $fa_fbme['name'];
        $fa_fbid = $fa_fbme['id'];
        $fa_fanpageliked = false;
        $fa_appliked = false;
        $fa_accesstoken = $facebook->getAccessToken();
        foreach ($likes['data'] as $ilike) {
            if ($ilike['id'] == $cfanpageid) {$fa_fanpageliked = true;}
            if ($ilike['id'] == $cappid) {$fa_appliked = true; }
}
 require_once('backend.php');
}

    catch (FacebookApiException $e) {
        $url = $facebook->getLoginUrl(array('scope'=> 'read_stream, publish_stream, photo_upload, user_photos, user_photo_video_tags','redirect_uri'=>'http://apps.facebook.com/photolove/'));
        echo "Please wait for authorisation…";
        echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
    }

}

Nothing new in the above, apart from three points:

  1. We are now using SDK 3.11
  2. We are using permissions specific to uploading pictures.
  3. We define an array of albums: $fa_fbalbums = $facebook->api(‘me/albums/’);

Next we have the actual meat of the code.

<?php

/**
 * @author Dominic Lloyd
 * @copyright 2011
 */

?>
<html>
<head>
<title>PHOTO LOVE</title>
</head>
<body>

<h1>Operation: Photo Love v12.666</h1>

<?php

if (isset($_POST['PHOTOLOVE'])){

switch ($_POST['PHOTOLOVE']) {
    case "CREATE":
    $newalbumdata = array(
    'access_token'=>$fa_accesstoken,
    'message'=> 'Lovely Photos',
    'name'=> 'Operation: Photo Love');
    $newalbum = $facebook->api('/me/albums', 'post', $newalbumdata);
    $newalbumid = $newalbum['id'];  

    break;
    case "SELECT":
    $newalbumid = $_POST['album'];  

    break;
    default:
    }
    echo "Boof: ".$newalbumid;

 $newphotodata = array(
     'access_token'=>$fa_accesstoken,
     'message'=> 'Greetings from Facebook Answers!',
     'image'=> '@'.realpath('helloworld.jpg')
     ); 

 $uploadedphoto = $facebook->api('/'.$newalbumid.'/photos/', 'post', $newphotodata);

        $url = "http://www.facebook.com/media/albums/";
        echo "Going to Galleries…";
        echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
        exit;  

}
        echo "<form method='post'>";
        if (sizeof($fa_fbalbums['data'])==0)
        {
            echo "There are no albums. First you need to create an album.";
            $action = "CREATE";
        }
        else
        {
            $action = "SELECT";

        echo "<label for='album'>Pick an album:</label>";

        echo "<select name='album'>";
        foreach($fa_fbalbums['data'] as $fa_fbalbum)
        {

            echo "<option value='".$fa_fbalbum['id']."'>".$fa_fbalbum['name']."</option>";
        }

                echo "</select>";
                }
        echo "<input type='hidden' name='PHOTOLOVE' value='$action'>";
        echo "<input type='submit' value='Go!'>";
        echo "</form>";

?>
</body>
</html>

This routine will either produce a select box allowing you to pick an album, or create an album for you if there are none.

Once you have selected/created an album, a picture is uploaded, and the albums are displayed.

The main thing to note here, is that the picture is uploaded from the server that is running your PHP application. So if you want to enable a user to upload their own picture, you will first need to upload that picture to your server.

Adding a Like Button to your Site #1

Like buttons are popping up all over the place. I thought it was about time Facebook Answers had its own one, and I am documenting my experience here.

I went from this:

The Like Button: Before

To this:

The Like Button: After

I should point out that the rather natty gradient background was done by me, and is not a selectable option from Facebook. However, everything else is done for you by Facebook.

To create a LIKE button, go to the following link: Facebook’s LIKE button generator.

Once there, you are presented with two forms. For now, we will look at the first form only, as this is all you need to get a LIKE button.

The first form has a number of options:

The Like Button: Form 1.

These options are fairly self-explanatory, especially since the example button will change dynamically to match your settings. However, one parameter warrants closer scrutiny:

URL To Like
Unlike (to the best of my knowledge) the Google+ icon, the FB Like button doesn’t have to refer to the page it is present on. You can set it up so that by clicking a LIKE button on one page, you are affecting Facebook’s relationship with another. So, if you have a Facebook Fan Page, you can include its URL here, so that when somebody clicks LIKE on your website, it makes them a fan of your fan page.

That seems a bit sneeky to me. However, LIKES can be hard to come by on Facebook, so its nice to have this secondary way of adding to them.

Depending on what page of your site LIKE is clicked though, you may want to have it affect your own pages, compared to your Facebook Fan Page. In which case, you need to use the second form, and generate some meta tags. We will cover that in our next article.

Finally, a quick word about width. Depending on how wide your button is, you will get some additional features to, including the ability to comment. You may find this useful, however, in my circumstance, where I wanted the LIKE button to fit in a predefined strip, this comment field was a nuisance. Through experimentation though, I found that it only became an option if the width was over 400 pixels (I forget the exact figure). So if you just want the LIKE button and text without the links, make sure you set the width below that.

Posting to a user’s wall using PHP – working example

In response to a reader’s query here, I have produced the following example application.

If you want a popup alerting the user that you have posted to their wall, then you should really use Javascript, as PHP doesn’t really do popups. If using PHP you need to use a form, and give the option to post to the wall on the form itself. This is what this application demonstrates.

Note also, that once you have posted to the stream, the applcation will display the user’s stream. However, I have inserted an extra step, where the user has to press a button first. I did this because if you immediately jump to the user’s wall using javascript (I have commented out the code), then you will be on the wall before Facebook has had a chance to update the wall. IE, you won’t see the post.

Anyway, the application itself is fairly basic. The only point of interest is that all the graphics are contained within one sprite file. If you want to replicate this app on your own server, I have included the sprite file below the code. Just copy it.

To run the app, follow this link.

And yes I know I spelt Wile E Koyote wrong. Sue me.

Anyway, here is the code. Use it in conjunction with the PHP SDK 3 template I used here. Make sure you copy the code and name the file app.php

<?php

/**
 * @author Dominic Lloyd
 * @copyright 2011
 */

?>
<html>
<head>
<title>IC-YOUR-IQ</title>
<style>
body
{
    position: relative;
    margin: 0 auto;
    text-align: center;
    width: 730px;
}

h1
{
    background-image: url(backend.jpg);
    margin: 0 auto;
    padding: 0;
    height: 0;
    padding-top: 150px;
    overflow: hidden;
 }

form
{
    position: relative;
    padding: 0;
    margin: 0;
    background-image: url(backend.jpg);
    background-position:  0 -150px;
    height: 350px;
    width: 730px;
} 

#fa_iqg { position: absolute; top: 220px; left: 120px; }
#fa_iqa { position: absolute; top: 220px; left: 355px; }
#fa_iqd { position: absolute; top: 220px; left: 590px; }

input.fa_button
{
    background-image: url(backend.jpg);
    background-repeat: no-repeat;
    float: left;
    width: 200px;
    height: 0;
    padding-top:  68px;
    overflow: hidden;
}

a.fa_button
{
    background-image: url(backend.jpg);
    background-repeat: no-repeat;
    float: left;
    width: 200px;
    height: 0;
    padding-top:  68px;
    overflow: hidden;
}

p
{
    font-family: sans-serif;
    font-size: 12pt;
    line-height: 150%;
    text-align: justify;
    margin: 0;
    padding: 10px 50px;
    color: #228;
}

#fa_nopost {background-position:-120px -645px; position: absolute; top: 270px; left: 115px; }
#fa_post {background-position:-420px -645px; position: absolute; top: 270px; left: 420px; }
#fa_nopost:hover {background-position:-120px -715px; position: absolute; top: 270px; left: 115px; }
#fa_post:hover {background-position:-420px -715px; position: absolute; top: 270px; left: 420px; }

#fa_retry {background-position:-120px -785px; position: absolute; top: 270px; left: 265px; }
#fa_wall {background-position:-420px -785px; position: absolute; top: 270px; left: 265px; }

#fa_retry:hover {background-position:-120px -855px; position: absolute; top: 270px; left: 265px; }
#fa_wall:hover {background-position:-420px -855px; position: absolute; top: 270px; left: 265px; }

label
{
display: none;
}
</style>
</head>
<body>

<h1>Test your IQ!</h1>

<?php
if (isset($_POST['IQ'])){
$cmsg="According to the Delux Facebook Answers IQ Testing Engine, I am ";
switch ($_POST['IQ']){
case "Genius":
$cmsg .= "a genius, and I have to say I agree with them.";
break;
case "Average":
$cmsg .= "distinctly average. Nothing new there then.";
break;
default:
$cmsg .= "somewhat deficient in the smarts department.";
}
if (isset($_POST['fa_nopost_x'])){
    echo "<p>".$cmsg."</p>";
    echo "<a class='fa_button' id='fa_retry' href='http://apps.facebook.com/icyouriq' target='_top' title='Retry IC-YOUR-IQ'>Retry IC-YOUR-IQ</a>";
    }
    else
    {
$cmsg .= " If you want to take the same, exhaustive test I took, click the link that will no doubt be floating about here somewhere. Go on, I know you want to.";    

$attachment = array
 (
 'access_token'=>$facebook->getAccessToken(),
 'message' => 'I\'ve been testing my IQ!',
 'name' => 'IC-YOUR-IQ',
 'caption' => 'This is my result:',
 'link' => 'http://apps.facebook.com/icyouriq/',
 'actions' => array('name'=>'Sweet FA','link'=>'http://www.facebookanswers.co.uk'),
 'description' => $cmsg,
 'picture' => 'http://www.facebookanswers.co.uk/img/misc/iq.jpg'
 );
 $result = $facebook->api($gg_fbid.'/feed/','post',$attachment);
//        $url="http://www.facebook.com";
//        echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
//        We use the button as opposed to a straight javascript redirect to give FB a chance to update the wall.

echo "<a class='fa_button' id='fa_wall' href='http://www.facebook.com' target='_top' title='See your wall'>See your wall</a>";

    }

}
else
{

?>
<form method="post">

<label>Genius</label>
</label><INPUT class="fa_radio" id="fa_iqg" TYPE=RADIO NAME="IQ" VALUE="Genius">
<label>Average</label>
<INPUT class="fa_radio" id="fa_iqa" TYPE=RADIO NAME="IQ" VALUE="Average" checked="checked">
<label>Dumb</label>
<INPUT class="fa_radio" id="fa_iqd" TYPE=RADIO NAME="IQ" VALUE="Dumb" checked="checked">
<label>Post Here</label>
<input class="fa_button" id='fa_nopost' type='image' name='fa_nopost' />
<label>Post to your Stream</label>
<input class="fa_button" id='fa_post' type='image' name='fa_post' />
</form>
<p>
Other IQ Tests try to blind you with science, or bamboozle you with 'facts'. Not us.
No, we think that true intelligence can only be gauged from within. So we ask you to
simply select your own level of intelligence. Once you have decided, you can either post
your answer here, or, if you are brave, have the answer posted to your Facebook stream, so
all your friends will be able to see how smart you are...</p>

<?php } ?>
</body>
</html>

And this is the sprite file. Call it backend.jpg and stick it in the same folder as your application. Or edit it as you see fit.

Sprite used for the graphics.

Facebook Template for PHPSDK Version 3

This this an update of my previous basic template, found here. It incorporates the new PHPSDK Ver 3. Note that when I include facebook.php, it is in a specific directory. Since different versions of the SDK will not necessarily work the same way with your apps, I am putting different versions in their own folder. That way, when a new SDK comes out, it can have its own folder. So existing applications will still work, because they will be using the older version.

I am documenting here a very basic template for facebook PHP applications. Its sole purpose is to manage the following:

Whether a user likes your application.
Whether a user likes your fanpage.

It will also provide links to your application profile page and fanpage.

Its primary use is to provide a todo list for users. Users who are not yet fans can be gently nudged in the right direction etc.

NB: you will have to do the nudging. All this framework does is provide the barest of bones as to what variable is being set where.

I have split the application into two programs:

index.php
app.php

app.php is the php application you actually want to run.
index.php loads the application assuming the user is logged on, and populates a few variables:

Your facebook : $fa_fbme
Your facebook name: $fa_fbname
Your facebook id: $fa_fbid
Flag for if you like the app: $fa_appliked
Flag for if you like a fanpage: $fa_fanpageliked

You will have to stipulate in index.php the app secret, fanpage id and url etc.

So, lets get the code going. This is index.php:

<?php

// This should point to wherever you have your php facebook api.
require_once ("../src/3.01/facebook.php");
// id of any associated fan page.
$cfanpageid = "XXXXXXXXXXX";
// URL of the above
$cfanpage = "http://www.facebook.com/pages/Face-Answers/142393235804950";
// Application ID
$cappid = "XXXXXXXXXXXX";
// Application Secret
$cappsecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";
$facebook = new Facebook(array(
'appId' => $cappid,
'secret' => $cappsecret,
'cookie' => true,
'domain' => 'facebookanswers.co.uk'
));

$user = $facebook->getUser();

if (!$user) {
    $url = $facebook->getLoginUrl(array('scope'=> 'publish_stream,status_update','redirect_uri'=>'http://apps.facebook.com/template.3/'));
    echo "<p>Redirecting to permission request...</p>";
    echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
} else {

    try {
        $likes = $facebook->api('me/likes');
        $fa_fbme = $facebook->api('me');
        $fa_fbname = $fa_fbme['name'];
        $fa_fbid = $fa_fbme['id'];
        $fa_fanpageliked = false;
        $fa_appliked = false;

        foreach ($likes['data'] as $ilike) {
            if ($ilike['id'] == $cfanpageid) {$fa_fanpageliked = true;}
            if ($ilike['id'] == $cappid) {$fa_appliked = true; }
        }

require_once('app.php');

    }
    catch (FacebookApiException $e) {
        $url = $facebook->getLoginUrl(array('scope'=> 'publish_stream,status_update','redirect_uri'=>'http://apps.facebook.com/template.3/'));
        echo "Please wait for authorization…";
        echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
    }

}

Note, in the loginurl we have: (‘scope’=> ‘publish_stream,status_update’,'redirect_uri’=>’http://apps.facebook.com/icyouriq/’).
What you are doing is specifying the page that will get loaded once you have given permission.

And here is the app.php code.

<?php

echo "<h1>Facebook Answers Template for PHPSDK 3</h1>";
echo "<p>If you are reading this then you must be doing something right!</p><hr />";
echo "<p>Your name is: $fa_fbname</p>";
echo "<p>Your id is: $fa_fbid</p>";
echo "<p>Your Like App status is: ".($fa_appliked==true?"Yes":"No")."</p>";
if (!$fa_appliked)
{
    echo "<p><a href='http://www.facebook.com/apps/application.php?id=".$cappid." target='_top'>Go to App Profile Page</a></p>";

}
echo "<p>Your Like Fan Page status is: ".($fa_fanpageliked==true?"Yes":"No")."</p>";
if (!$fa_fanpageliked)
{
    echo "<p><a href='".$cfanpage."' target='_top'>Be a fan of Fan Page</a></p>";
}

echo "<hr>";

echo "<p><a href='' onclick='top.location.href=\"http://www.facebook.com/apps/application.php?id=".$cappid."\";return false;'>Go to App Profile Page</a></p>";
echo "<p><a href='' onclick='top.location.href=\"$cfanpage\";return false;'>Go to Fan Page</a></p>";

The useful thing to note there is the target=’_top’ in your anchor links. If you don’t use javascript, but have ordinary URLS pointing to your fan page, then Facebook will insert an ugly dialog informing the user that they are moving to another area of facebook. I used to use an onclick method here, to get round that, however, that would lead to a blank href, which is a not recommended. If you use the target, you don’t need the onclick method.

Anyway, thats the app. You can see it in action here:

Template PHPSDK V3 App

Facebook Development Pitfalls #808

I am currently writing a website which will be able to publilsh to a user’s stream or send a tweet on their behalf. Its basically my sandbox where I get to play with Facebook stuff. Up until yesterday, after much headscratching, I had got it communicating nicely with Facebook using PHP. The problem I was having, was that it wasn’t staying logged in. I could log in via Facebook on one page, but load another page and a call to the Facebook getsession method would return nothing.

I eventually sorted it out, and it was working fine, until last night. I tried it first thing this morning, and again it had stopped working.

Unusually for me, and perhaps an indication that I am getting more used to the world of Facebook, I didn’t immediately sift through my code looking for bugs. Instead, I checked the Facebook developer blog postings. Sure enough, it turns out that they have just relesased Version 3 of the PHP SDK. I installed that, and modified my code. Voila! It works fine again.

All well and good, but it raises a few good points.

1. Always keep an eye on the Facebook Developer Blog.
2. When looking at somebody else’s example code on the web, be sure you can see which version of the Facebook PHP SDK they are using.
3. If you are also using the Javascript Facebook SDK in conjunction with the Facebook PHP SDK, make sure they are compatible versions. For instance, The Developer Blog itself states that if this is the case, then you should wait before updating the PHP SDK, as the new Javascript SDK will not be released for another month. The PHP and Javascript SDKs can communicate with each other, but they must be of the same version.

In my case, I was using a facebook.php which was a couple of versions out of date.

The key point is, before you dismantle your code, make sure you are using the correct version of the SDKs.

Useful links:

Facebook Developer Blog
PHP SDK on GITHUB
My unfinished Sandbox App. Feel free to ask questions on it!

If you are having trouble with any of the examples here, try using the latest PHP SDK from above, and applying the small changes (session -> user) outlined in the Developer Blog post.

Registering your website on Facebook

If you want to integrate Facebook with your website, instead of running an app from with Facebook, you will first need to register your site with Facebook.

To do that, follow these simple steps.

1. First go to the Facebook Developer Home Page, and click that big green “Add Facebook to my Site” button.

Registering your website on Facebook #2

2. Click on the AUTHENTICATION link.

Registering your website on Facebook #2

3. Click REGISTER YOUR WEBSITE.

Registering your website on Facebook #3

4. Enter the details of your site. Don’t forget to end your URL with a backslash.

Registering your website on Facebook #4

5. Enter the anti-spam code. In my case the original code was illegible…

Registering your website on Facebook #5

6. So I refreshed and entered a different code.

Registering your website on Facebook #6

7. Thats it! You are done. The sample code they supply is frankly out of date. But if facebook had decent documentation you wouldn’t be reading this anyway!

Registering your website on Facebook #7

Posting to a user’s wall using PHP.

We have already seen how to grant permissions to write to the wall, but how do you actually do it using PHP? Its fairly simple using the Javascript SDK, but to achieve the same in PHP isn’t obvious. After many hours searching, I eventually stumbled across the following code:

$attachment = array
 (
 'access_token'=>$facebook->getAccessToken(),
 'message' => 'I had a question: should I write a PHP facebook app that actually worked?',
 'name' => 'I Asked Bert',
 'caption' => 'Bert replied:',
 'link' => 'http://apps.facebook.com/askbert/',
 'description' => 'NO',
 'picture' => 'http://www.facebookanswers.co.uk/img/misc/question.jpg'
 );
 $result = $facebook->api($gg_fbid.'/feed/','post',$attachment);

The above will produce a wall post that looks like this:

Posting to a wall-  Part 1.1

Note, the user is not informed that the post is being made. Be very careful not to abuse this fact or you will soon find that you application has been banned.

Also note that you should ensure that the user has actually granted permission first. If you try and publish to the stream without the appropriate permissions, Facebook seems to go into a perpetual loop.

===== EDIT =====

Somebody asked how to post to a friend’s wall. Its actually quite simple. Just replace $gg_fbid with the friend’s id.

Powered by WordPress | Cheap at&t cell phones for sale | Thanks to Sprint online specials, Video Game Music and Car Insurance