You are viewing our Forum Archives. To view or take place in current topics click here.
[Quick-Tutorial] How To make a facebook app.
Posted:

[Quick-Tutorial] How To make a facebook app.Posted:

AoC
  • TTG Addict
Status: Offline
Joined: Feb 06, 201014Year Member
Posts: 2,038
Reputation Power: 151
Status: Offline
Joined: Feb 06, 201014Year Member
Posts: 2,038
Reputation Power: 151
With more than 300 million active users and 50% of them using it every day (source), Facebook can be an interesting way to make some viral marketing.

One of the most effective ways is developing an application users (and users friends and friends of users friends and) will use every day.

This tutorial will guide you through the creation of a simple application that will display how many male and female friends do you have.

Requirements

To develop a Facebook application with this tutorial, you will need:

* An active Facebook account
* An hosting plan supporting php

Getting started

Go to developers area and click on Set Up New Application [ Register or Signin to view external links. ]

[ Register or Signin to view external links. ]

Give a name to your application and agree terms.

[ Register or Signin to view external links. ]

Then, Facebook will create an API key and a secret key. Write them down (well, its not necessary since you will always find them in this page, but having something to write down makes me feel like Im dealing with something important).

At this time the application is ready to run, but you can add more information and icons.

When done, go to Canvas page

[ Register or Signin to view external links. ]

At this time your application is ready to be executed.

[ Register or Signin to view external links. ] and copy the content of facebook-platform -> php to the Facebook application directory in your server the same path of Canvas Callback URL.

Your directory now should look like this:
[ Register or Signin to view external links. ]

Now, its time to create the application itself:

<?php
 
require_once 'facebook.php';
 
$appapikey = 'xxxx';
$appsecret = 'xxxx';
 
$facebook = new Facebook($appapikey, $appsecret);
 
$user_id = $facebook->require_login();
 
$friends = $facebook->api_client->friends_get();
 
echo "<p>Hello <fb:name uid=\"$user_id\" useyou=\"false\" linked=\"false\" firstnameonly=\"true\"></fb:name>, you have ".count($friends)." friends";
 
foreach($friends as $friend){
     $infos.=$friend.",";
}
 
$infos = substr($infos,0,strlen($infos)-1);
 
$gender=$facebook->api_client->users_getInfo($infos,'sex');
 
$gender_array = array();
 
foreach($gender as $gendervalue){
     $gender_array[$gendervalue[sex]]++;
}
 
$male = round($gender_array[male]*100/($gender_array[male]+$gender_array[female]),2);
$female = 100-$male;
 
echo "<ul><li>Males: $male%</li><li>Females: $female%</li></ul>";
 
?>


Line 3: including Facebook library

Lines 5-6: Declaring variables with API key and secret code yes, the two codes seen before

Line 8: Initializing a Facebook API

Line 10: Requiring the user to be logged into Facebook before using the application. If they are not logged in they will first be directed to a Facebook login page and then back to the applications page. Then save the user unique id into $user_id variable

Line 12: Storing in the $friends array the unique id of all friends of yours

Line 14: This is the first FBML tag we see: Fb:name renders the name of the user specified by uid attribute. In this case, it will display your name.

Lines 16-20: Creating a string with all of your friends ids separated by comma, such as uid1,uid2,uid3,...,uidn

Line 22: users_getInfo returns a wide array of user-specific information for each user id passed. As you can see, I pass the whole list of friends and I only want to know their sex.
Line 24: Creating an array where I will store all genders

Line 26-31: Determining the % of each gender (male or female) in my friends list. You can see some additional math because sex value can be blank

Line 33: Displaying the results

Now that your application is completed, you can submit it to the Application directory. Before you are able to do it, your application must have at least 5 total users or 10 monthly active user.

It should output something like that
Hello Malwarebytes, you have 49 friends
Males: 53.66%
Females: 46.34%

Go Look at your finished app.

Warning: During the latest day there is a known bug called facebook auth_token loop that wont allow you to run the application. If you experience problems, simply check back later.
#2. Posted:
M0D1F13D
  • TTG Senior
Status: Offline
Joined: Sep 06, 201013Year Member
Posts: 1,069
Reputation Power: 47
Status: Offline
Joined: Sep 06, 201013Year Member
Posts: 1,069
Reputation Power: 47
Aren't there alot of ways you could exploit your access to the users? i.e storing their account info...
#3. Posted:
iNull
  • TTG Senior
Status: Offline
Joined: May 10, 201113Year Member
Posts: 1,011
Reputation Power: 59
Status: Offline
Joined: May 10, 201113Year Member
Posts: 1,011
Reputation Power: 59
Great tut im gonna do this thanks man
#4. Posted:
Experiment5X
  • TTG Senior
Status: Offline
Joined: Aug 14, 200914Year Member
Posts: 1,291
Reputation Power: 65
Status: Offline
Joined: Aug 14, 200914Year Member
Posts: 1,291
Reputation Power: 65
Please post the source next time so it doesn't give people the illusion that you made this tutorial [ Register or Signin to view external links. ]
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.