Create a Facebook application
Do you know Friend Interview?
It’s a Facebook application which asks a random question about a random friend of yours, and publish the result on his wall. I won’t publish a snapshot of such app since it’s full of rubbish and ads, but I am sure you know what I am talking about (and moreover there’s the link!).
You should know how to create a Facebook application, anyway I’ll post a recap here.
1) Go to http://www.facebook.com/developers/ and click on “Set Up New Application”.
2) Give a name to your application. You can give it any name as long as it does not infringe copyrights, agree to terms and click on “Create Application”.
3) On “Facebook Integration” panel give it a Canvas Page name (this must be unique), and in “Canvas URL” write the path on the folder on your server which will contain the application itself, set “Canvas Type” as “IFrame” and “IFrame Size” to “Auto-resize”, then press “Save Changes” and at the moment you are ready to create your application.
4) Download the Facebook API from GitHub and copy
Now everything is ready to develop your application. In this first part, we will ask for permissions and choose one random friend.
Create a new file called
Let’s see its meaning:
Line 3: including the required library.
Line 5: initializing the Facebook application. In the array you must pass the following elements:
Line 7: getting the session object. At this point, the script splits in two paths, according to $session value.
$session is NULL (lines 9-13)
If
$session is not NULL (lines 14-21)
In this case I put in
And that’s it, this is what you’ll get:
You can test it by yourself here: http://apps.facebook.com/
Now you know how to pick a random friend. During next step you will be able to ans
It’s a Facebook application which asks a random question about a random friend of yours, and publish the result on his wall. I won’t publish a snapshot of such app since it’s full of rubbish and ads, but I am sure you know what I am talking about (and moreover there’s the link!).
You should know how to create a Facebook application, anyway I’ll post a recap here.
1) Go to http://www.facebook.com/developers/ and click on “Set Up New Application”.
2) Give a name to your application. You can give it any name as long as it does not infringe copyrights, agree to terms and click on “Create Application”.
3) On “Facebook Integration” panel give it a Canvas Page name (this must be unique), and in “Canvas URL” write the path on the folder on your server which will contain the application itself, set “Canvas Type” as “IFrame” and “IFrame Size” to “Auto-resize”, then press “Save Changes” and at the moment you are ready to create your application.
4) Download the Facebook API from GitHub and copy
facebook.php
in the folder you specified in the Canvas URL.Now everything is ready to develop your application. In this first part, we will ask for permissions and choose one random friend.
Create a new file called
index.php
with this code:Let’s see its meaning:
Line 3: including the required library.
Line 5: initializing the Facebook application. In the array you must pass the following elements:
appId
: the application IDsecret
: the application secretcookie
: (optional) boolean true to enable cookie supportdomain
: (optional) domain for the cookiefileUpload
: (optional) boolean indicating if file uploads are enabledLine 7: getting the session object. At this point, the script splits in two paths, according to $session value.
$session is NULL (lines 9-13)
If
$session
is NULL
, we need to redirect to the login url to let the player allow the application use his personal information. The redirection is made with a simple javascript, using getLoginUrl
.$session is not NULL (lines 14-21)
In this case I put in
$friends
array an array with all friends names and Ids, then I randomly pick one of them and display its name and a possible question.And that’s it, this is what you’ll get:
You can test it by yourself here: http://apps.facebook.com/
Now you know how to pick a random friend. During next step you will be able to ans
No comments:
Post a Comment