Facebook Programming: Facebook Platform
Facebook Application Programming Step by step tutorial - part 1. Facebook is an incredible site. At the time this tutorial was written, this site reaches ranking second only to Google in the achievement of visitors. What does it mean? Facebook could attract so many visitors. This site even has defeated Friendster friendship site that had been rampant.
But here we are not going to discuss the problem of how to collect friends through Facebook. We will be concentrated into our problems how to make an application on Facebook.
In facebook, we know the term Facebook platform. Said about platform is very common we hear. Yes, many people say about the "platform". The politicians we like to discuss about the party platform, the coalition must be based on platforms, and so on. The soccer players also discuss platform play. Techniques and strategies are part of the platform to win the game.
Figure 1.1 News Feed Application
Facebook Application
How many applications do you get after registering on Facebook. You can check with the following steps:
- Log in to your Facebook page.
- In the lower left corner, click the Applications button.
You'll get a menu display as shown in Figure 1.2. The menu displays the applications that you can use right now.
Figure 1.2 Faceboook Main Menu
- To search for other applications, you can click the link Browse More Applications. To edit an existing application, you can click the Edit Applications link.
Figure 1.3 List of applications used by a user
From the explanation above, is can you imagine what is meant with Facebook Platform? Yes, Facebook Platform's like a house foundation on which to build the rooms. Fun, home owners can build rooms by knock down model. He can put any part of the building and unload at any time he likes.
Figure 1.3 shows an example list of applications used by a user. He can display a list of applications based on the intensity of usage, which has applications in bookmark it, has been authorized, and so on. Then you can adjust settings on the application. So, this practically is the central of your application control.
Figure 1.4 Setting of application
Third Party Application
Well, fun, Facebook does not only display their application himself. Anyone can create and run applications on Facebook. This is one of the uniqueness of Facebook. this site is not only friendship site that collects just friends, but it also could be developed in accordance with user needs.
You can use Facebook when saturated. Even at the time did not want to meet or greet friends. You can search for game applications on Facebook. One of the popular game is Farmville. In this game, you're not just playing alone, you can also neighbors and help your neighbors. Thus, the concept used in applications is community development.
Figure 1.5 FarmVille game application
So, What is Facebook Platform?
By definition, Facebook platform can be interpreted: framework programming that enables application developers create applications that can interact and integrate with Facebook core services. Example, application named Super Wall application.
Figure 1.6 Supperwall application
Super Wall application is not created by Facebook team but by other developers. In the application, you can display wall in a different format. You can display the status of your friends in this application. This means, the application can interact with your data on Facebook service standards.
Mmm ... you should mention that Facebook is a place to integrate all the applications you need. You can build financial applications, appointments, and other business applications. You can use Facebook as a portal of all the data you need. That is the advantage of the Facebook platform.
Facebook Application Architecture
Well, we'll compare how common web application architecture with applications on Facebook. Below is a standard web architecture:
Figure 1.7 Standar web architectur
When you want to open a web page, you send an HTTP Request to the server. On the server there will be a process involving the application and database. The results of this process, an HTML document will be sent to your browser.
Now we see how the Facebook platform works. When you open an existing application on Facebook, you send an HTTP Request to the facebook server. Your request will be forwarded to the owner of the server application. There is some information (eg user id) that will be requested from the server to the server application for Facebook. Next, Facebook server will respond and send data to the server application. After the application is processed on the server, it sends the document in a format that is sent to the FBML Facebook servers. By Facebook document is processed and produces an HTML document that is sent to your page.
Figure 1.8 Facebook architectur
Facebook Framework Components
In the Facebook platform, there are parts where you will incorporate in your code:
- Facebook API
- FBML (Facebook Markup Language)
- FQL (Facebook Query Language)
- Facebook Javascript
Facebook API
API stands for Application Programming Interface. Facebook API is the heart of your application. Facebook API is a Web services programming interface to access the main Facebook services (profile, friends, photo, event) and the function of Facebook (login, redirect, update the view). API is REST-based architecture (Representational State Transfer).
Facebook Markup Language
Facebook Markup Language is a language like HTML but versions of Facebook for display a canvas page in Facebook. Here are three facts about FBML:
- FBML also contains a subset of HTML elements. Common elements such as p, ul, and h1 is also part of FBML.
- FBML also support for script and style elements. Javascript is not supported in the usual script. However, some javascript code can be supported on the Facebook Javascript. Elements of style can not you use to access the external style sheets. You can only use internal CSS.
- FBML provides some extensions for the user interface (UI) in particular.
Facebook Query Language
Facebook Query Language (FBQL) is a SQL-based interface to the Facebook data. Through FBQL, you can access many tables in the database such as Facebook users, friend, group, group_member, event, event_member, photo, albums, and photo_tag. FBQL is a query language similar to the SQL standard, but there are some limitations:
- SELECT statement must be one table at a time
- Join query is not allowed
- A query must be indexed
Facebook JavaScript
As mentioned above, Facebook does not support Javascript elements standard in the script. However, there are some Javascript code (which in a very limited number) that can be run on Facebook through the Facebook JavaScript. Here's the difference between the Facebook Javascript and Javascript:
- Facebook provides an alternative implementation of the DOM using JavaScript DOM standard.
- Many implementations FBJS objects with a standard Javascript, but there are many differences.
- When processing the code in the script element, he will relate the function and variable names of the application.
Well, you now understand a little what it Facebook Platform. Now it's time to begin to know how to use it.
Facebook Programming: My First Facebook Application
Facebook Application Programming Step by step tutorial - part 2. You have to know at a glance about the Facebook platform in the previous post. Now it's time for you to taste the Facebook platform. In this tutorial, we will begin to create a simple Facebook application. Let's get started!
In this post, you will learn how to make an application on Facebook through stages:
- Registration application
- Use Facebook Platform
Registering Your Application on Facebook
Before you start making the application, you must register your application on Facebook. Why be registered? Because, you need the API Key in making an application on Facebook. API Key is the key in which your application can interact with services on Facebook. It kind of password for your application.
Think of a theme prior to the application that you created. Next consider a name for the application. The name will be a brand for your application. After that do registrations. Here are the steps to register the application on Facebook:
- Open your browser. Point to www.facebook.com / developers.
If you are not logged in, then the page that appears is the login page. You need to login. Figure 2.1 shows the front page facebook.com/developers, where you will start making applications.
Figure 2.1 Front page facebook.com/developers
- Click the Set Up New Application located in the upper right.
Notice the arrow in Figure 2.1. Next you will get form as in Figure 2.2.
Figure 2.2 Form create new applications
- Enter the name of the application on the Application Name item.
Consider carefully the use of the name. These names will be the brand of your application. He will appear on Facebook pages. Suppose that in this example I named Yumie Tester.
- Select items Agree to declare that you have read and accept the rules created by Facebook.
If you want to read the rules (Facebook Terms), click the link Terms Facebook. We recommend that you read to find out the boundaries of the use of Facebook.
- Click the Create button Application.
Before clicking the Create Application button, make sure you have selected items Agree. If not, you will not be able to continue.
After clicking the Create Application button, you will get an application form setting as you can see in Figure 2.3. If you look at the left side of the form, a menu will appear. The menu shows the grouping of items settings.
Figure 2.3 application settings menu
Well, we'll start from setting the basic things in the Basic menu.
Figure 2.4 form the basic settings
- Write a brief description of your application is on the Description field.
Make a statement with the marketing language. Make it interesting and gives a clear picture of the application. The hope, could attract a lot of Facebook users to use the application.
- To display your application icon, click the link Change your icon.
This step is optional. You may pass. But if you do, you'll get a form as shown in Figure 2.5.
Click the Browse button to take a picture you want to make icons. Image format that you can upload a JPG, GIF, or PNG. File icons are also not exceed 5 MB. Size to be used is 16 x 16 pixels. If your image exceeds the size will be adjusted by Facebook.
Check the item "I certify that I have the right to distribute this photo and that it is not pornography". Next click the Upload Image button. Wait a few moments. Once successful, the icon will appear on your setting page.
Figure 2.5 form to upload icon
- If you want to display the logo, click the link Change your logo.
This step is also optional. You can upload your logo or not. If you click on the link to upload a logo, you will get the form as shown in Figure 2.6.
Feel free to upload your logo image. Images can be formatted JPG, GIF, or PNG. Not exceed 5 MB. Maximum size 75 x 75 pixels. If more than would be adjusted by Facebook.
Check the item "I certify that I have the right to distribute this photo and that it is not pornography". Next click the Upload Image button.
Figure 2.6 Form to upload a logo
Figure 2.7 Picture icons and logos successfully uploaded
- If developernya more than one, you can add them to Developers field.
In this field, you can add more than one developer. Way by typing in a name other than your developers. You can register more than one name.
- Write your email in Developer Contact Email Address and User Support.
This is a medium of communication between the user and your application as an application developer. Through this channel, you will get feedback from your users. By default, will be listed email address you used to register on Facebook. But you can replace the need for this application alone.
- Click the Canvas menu.
There is some information that we deliberately let the first. The target here, you can create applications quickly without having to mess around a lot of settings. Detailed settings we will discuss as we develop the application.
Figure 2.8 menu item Canvas
- In item Canvas Page URL, add the name as the URL of your application in facebook.
This URL must be unique. There should not be the same application. Suppose that in this example I use the name "yumietester". So your URL application http://apps.facebook.com/yumietester/.
- On Canvas items Callback URL, type the address where you save your application.
Address here is the address of the server / hosting where you save the application. For example, http://fb.geniofam.com/ app. Facebook will access the page and retrieve content from that page.
- Render Method on the item, choose FBML.
Here we will use in making FBML Facebook application page.
- Click the Save Changes button.
Figure 2.9 Registration successful application
After saving these settings, you'll get a page like in Figure 2.9. In this page, you will find information on your application ID, IP Key and Application Secret. We recommend that you store the information meetings. That is the password for your application to communicate with the Facebook servers.
Getting Client Library File
Before you begin creating applications, you need a Facebook Client Library first. You must download it from the website Facebook. Here are the steps:
- Download the file in the client library developers http://www.facebook.com/ pages / apps.php.
Find the download link at the bottom right. Click the link Download the Client Library.
Figure 2.10 Link to download the client library file
Save the file to your local computer.
Figure 2.11 Download client library file
- Next extract (uncompress) the file.
You can use winrar or 7-zip to extract the file. After you extract, you will get a structure like Figure 2.12.
Figure 2.12 client library file structure after the extracted
You'll get a folder called facebook-platform. Inside the folder are two folders:
- footprints are examples of Facebook applications at PHP5.
- php is the folder that contains the PHP 5 library files .
Upload all the files to your server.
Upload Client Library Files to Server
Here I will demonstrate how to upload files to the server. The assumption, you have CPanel facilities in your hosting. I have a domain name geniofam.com. The application will be placed on the subdomain fb.geniofam.com/app. The following steps create a subdomain to start uploading the file:
- Open your domain cpanel page.
Suppose that in this exercise I use a domain geniofam.com. So to access cpanel address will be used http://www.geniofam.com/cpanel. You'll get a form to sign. You need to login.
- Open the pages of your subdomain.
After successful login, you will get the main page CPanel. Find the link on the Domains Subdomains.
Figure 2.13 Link subdomains on cPanel main page
- Create a new subdomains.
You'll get a form to create a subdomain. The number of subdomains you can create depends on the hosting policy (and of course the package you choose).
Fill in the name of the item Subdomain subdomain. While the document root is automatically written to the access path to the root of your subdomain. Click the Create button.
Figure 2.14 Creating a new sudomain
- Back to front page CPanel.
We will create an FTP account for your subdomain. For that go back to the front page CPanel.
- FTP Accounts Open page.
FTP Account link found on the Files. Next you'll get a form to register a new account as shown in Figure 2.16.
Figure 2:15 Link to this page FTP Accounts
- Write down the username for the new account.
Login item, type the username for the new account. If you're going to use it, then it merged with username @ domainname. For example, fb@geniofam.com.
- Specify the account password.
Enter the password for the account password on the item. Below the input box there are indicators that indicate whether a password is a strong password (not easily guessed) or not. Use a combination of letters, numbers and spaces. If you do not want to worry about passwords, please click the Generate Password button.
Figure 2.16 Form add FTP accounts
- Repeat password.
Retype the password in Password field (Again). This is to ensure that you remember the password that you specify.
- Determine the subdomain directory.
If you only allow them to access the ftp account specific subdomain the subdomain directory list. Consider three steps.
You can specify a disk space quota for the account. If not, you can let the unlimited.
- Click the Create FTP Accounts.
Wait a while until the new FTP accounts created. If successful, you will get a view as in Figure 2.17.
Figure 2.17 FTP Accounts successfully created
- Open your FTP program.
There are many FTP programs you can use. Here I use Fire FTP. An add-on (extra program) for Mozilla FireFox Brower. You can get it in http://fireftp.mozdev.org/. I love the Fire FTP, because it integrates with the FireFox browser. Although there are limitations in the feature.
Figure 2.18 Fire FTP FTP program in a FireFox browser
- Upload Client Library File.
Alternatively, you can use the included File Manager in CPanel. Here are the steps:
- Click the File Manager link on the main page CPanel.
File Manager link located in the Files group. If you use this, you do not need to unpack first. Because cPanel has a facility to extract the compressed file.
Figure 2.19 Link to the File Manager
- Select the Document Root for subdomains.
Figure 2.20 Selecting a subdomain
After clicking the File Manager, you will get a dialog box. Choose Document root for the subdomain you have created. Thus, the file manager will automatically display the file structure on the subdomain.
- Create a new folder named "app".
Once entered into the page file manager, a direct position on the subdomain you choose. In the subdomain directory has only cgi-bin directory.
Figure 2.21 The position in subdomain fb
Click the New Folder button to create a new folder. The button is in the toolbar at the top.
Figure 2.22 key create a new folder
After clicking the button on the toolbar, you'll get a dialog box. Write the name of the new folder on the New Folder Name the item. After that, click Create New Folder button.
Figure 2.23 Creating a new folder named app
- Open the app folder.
App folder you created successfully. To upload a file in the app folder, you must open the folder first. Way by double-clicking on the folder app.
Figure 2.24 Creating a folder app
- Opening the upload page.
After opening the app folder, now it's time you upload a file compression client library. Click the Upload button on the toolbar.
Figure 2.25 key file upload
- Upload file client library.
After opening upload page, click the Browse button. Select a file compressed client library that you want to upload. Once successfully uploaded, you will get a sign like in Figure 2.27. Close the upload page. Return to the page file manager.
Figure 2.26 Form upload files
Figure 2.27 File successfully uploaded
- Extracts client library files.
You should already have a file on the client library in the file manager. If not appear, you can click the Reload button.
After a look, click the file, then click the Extract button on the toolbar.
Figure 2.28 Select a file to be extracted
After clicking the Extract button, you'll get a dialog box. Click the Extract File (s) in the dialog box.
Figure 2.29 a confirmation dialog box to extract the location of the file
Wait a few moments to appear the dialog box that displays a list of files extracted. For example you can see in the picture 2:30.
Click the Close button to close it.
You've managed to upload and extract the client files on the library web server. Now you're ready to create your first Facebook application.
Next we will begin to write the code. Usually, I write computer code using an editor like Dreamweaver. After that just upload the web server. Techniques such as uploading the files we have done the above. So, we will not be discussed again.
Figure 2.30 The results of the extraction of client library files
Build My First Simple Application
Now you're ready to write your first code. Create a new file named index.php. Write the following code:
01 | <?php |
02 |
03 | // Get these from http://developers.facebook.com |
04 | $api_key = '2c73ae8529134aaaaaaaaaaaaaaaaaaa' ; |
05 | $secret = '3c041a7cbd797aaaaaaaaaaaaaaaaaaa' ; |
06 |
07 | include_once './facebook-platform/php/facebook.php' ; |
08 |
09 | $facebook = new Facebook( $api_key , $secret ); |
10 | $user = $facebook ->require_login(); |
11 |
12 | ?> |
13 |
14 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! |
15 | Wellcome to Yummie Tester! |
Upload the file on your web server. Put under the app folder.
To test this, point your browser to http://apps.facebook.com/yummietester or name that you have registered. The next display will appear as in Figure 2.31.
Figure 2.31 Confirmation of application will access your data
Click the Allow button to allow you to open the application. Next you'll get a view like Figure 2.32.
Figure 2.32 A preview of Yummie Tester
Congratulations you have successfully created a simple application on Facebook.
Showing Friends
After a successful showing simple application, we will try to make it a little more cool. Ie, by displaying a list of your friends. Change the code in index.php in app became like this:
01 | <?php |
02 |
03 | // Get these from http://developers.facebook.com |
04 | $api_key = '2c73ae8529134d74eaaaaaaaaaaaaaaa' ; |
05 | $secret = '3c041a7aaaaaaaaaaaaaaaaaaaaaaaaa' ; |
06 |
07 | include_once './facebook-platform/php/facebook.php' ; |
08 |
09 | $facebook = new Facebook( $api_key , $secret ); |
10 | $user = $facebook ->require_login(); |
11 |
12 | ?> |
13 | <h1>Yummie Tester</h1> |
14 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
15 | Your id : <?php echo $user ; ?>. |
16 |
17 | You have several friends:<br> |
18 | <? |
19 | $friends = $facebook ->api_client->friends_get(); |
20 | ?> |
21 |
22 | <ul> |
23 | <? |
24 | foreach ( $friends as $friend ){ |
25 | echo "<li><fb:name uid=\"$friend\" useyou=\"false\"></li>" ; |
26 | } |
27 | ?> |
28 | </ul> |
Code to display the friend is located at:
1 | $friends = $facebook ->api_client->friends_get(); |
2 | foreach ( $friends as $friend ){ |
3 | echo "<fb:name uid=\"$friend\" useyou=\"false\">" ; |
4 | } |
After you run, you will get something like this:
Figure 2.33 Displaying a list of friends
Application Profile
Every application has an application of a profile page. On this page you can put information on the application. In addition, on the same page, there is a wall where users can interact with each other. One example can you see in Figure 2.34. This page is your front application information page. There is a wall where visitors and users can interact.
Figure 2.34 About page of a gaming application
To view the profile page of your application, you can follow the steps below:
- Open http://www.facebook.com/developers address in your browser.
- Click on the link See My Applications.
After clicking the link, you will get a list of pages that you create the application.
Figure 2.35 Link to go to the application list pages
- Select the application.
In the application list page, there may be some applications that you have created. Choose an application you want to see the profile.
Figure 2.36 page list of applications
- Click the link View Application Profile.
To edit the information in the application profile, you can click the Edit Application Profile.
Figure 2.37 The main page to edit and configure the application profile page
For example, we will try to edit the application information. For that click the pencil icon in the Application Information. Select the edit link in the popup menu that appears.
You'll get a page to edit the application information as in Figure 2.38.
Figure 2.38 Form editing application information
The following information from the form above:
- Description of Application is an explanation of the application that you create.
The explanation should include usability, features, and benefits of application you create. The more solid the more you make a good sentence.
- Select the appropriate category for your application in Category.
If you make just for practice, you can not fill it. But if you create a real application, you should choose the appropriate category for the application.
- Select whether the information the company or individual developers to be shown on the items Developer Information.
If you choose Individual Developers, then that will appear is a list of developers who build these applications. Developer's name has been at the time you filled out an application configuration. Next you are asked to fill in an explanation of these developers.
- Fill in your company name Company Name item.
You can fill out the information a company or organization that embodies the developers.
- Write the company's website at items Company Website.
If the company or organization has a website, you can publish it.
- Explain about the items the company About the Company.
You can expose a company profile or your organization in this field. Here, you can all your company's promotion of it.
After that, you can click the submit button to save the changes that information.
To change or add a logo, you can click the tab Step 2: Picture.
Facebook Application Programming Step by step tutorial - part 3. In the previous post, you have tried to create a simple Facebook application. You also use Facebook API. API is a means to communicate between programs. For example, in the previous exercise, you create a program to display a list of friends on Facebook. You can make these programs because of the API. You use Facebook API to display data from Facebook servers.
Currently, the API is the trend in the programming world. Not only are making Facebook API. Google, Amazon, Yahoo, and others also provide an API. With this API, you can create applications by using the features or existing data on their servers.
Calling API
In this post, we will discuss further the API that is on Facebook. We will start from analyzing the program code that we wrote earlier. We'll see, where we use the Facebook API.
01 | <?php |
02 |
03 | // Get these from http://developers.facebook.com |
04 | $api_key = '2c73ae8529134aaaaaaaaaaaaaaaaaaa' ; |
05 | $secret = '3c041a7cbd797aaaaaaaaaaaaaaaaaaa' ; |
06 |
07 | include_once './facebook-platform/php/facebook.php' ; |
08 |
09 | $facebook = new Facebook( $api_key , $secret ); |
10 | $user = $facebook ->require_login(); |
11 |
12 | ?> |
13 | <h1>Yummie Tester</h1> |
14 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
15 | Your id : <?php echo $user ; ?>. |
16 |
17 | You have several friends:<br> |
18 | <? |
19 | $friends = $facebook ->api_client->friends_get(); |
20 | ?> |
21 |
22 | <ul> |
23 | <? |
24 | foreach ( $friends as $friend ){ |
25 | echo "<li><fb:name uid=\"$friend\" useyou=\"false\"></li>" ; |
26 | } |
27 | ?> |
28 | </ul> |
Where do you call the Facebook API?
This is the Object Oriented Programming (OOP). If you do not know about OOP in PHP, I recommend you read this post first. Let more deep understanding of the API. However, if you remain determined to continue to learn Facebook programming is also fine. With a little squeeze your brain, you will come to understand what it is OOP.
Back again to the code above. At the beginning of the line, you are prompted to insert the API Key and secret codes. This kind of entering a username and password database.
1 | $api_key = '2c73ae8529134aaaaaaaaaaaaaaaaaaa' ; |
2 | $secret = '3c041a7cbd7aaaaaaaaaaaaaaaaaaaaa' ; |
next, we call Facebook client library:
1 | include_once './facebook-platform/php/facebook.php' ; |
On the client library, there is a class code to access Facebook. You must call and initialize a Facebook class.
1 | $facebook = new Facebook( $api_key , $secret ); |
Next, do check whether the user is already logged or not. If have login, you'll get the ID of the user. User ID is inserted into the variable $ user.
1 | $user = $facebook ->require_login(); |
Well, pay attention to the next line:
1 | $friends = $facebook ->api_client->friends_get(); |
This is where you begin to use the Facebook API. You call the method api_client(). Above, you call the Facebook API is called: friends.get. The results of the use of these APIs is a list of ID's friends are accommodated in the variable named $friends. Next you want to display in the browser with the code:
1 | foreach ( $friends as $friend ){ |
2 | echo "<li><fb:name uid=\"$friend\" useyou=\"false\"></li>" ; |
3 | } |
Maybe you're wondering, his name is friends.get, but why written friends_get()? Yes, for the PHP programming standards, Point (dot) replaced with underscores. Here's example:
- Events.get written events_get()
- Friends.get written friends_get()
- Comments.get written comments_get()
Facebook Application Programming Step by step tutorial - part 4. In the previous exercise, you've tried one method in Friends: get. There are several methods available to Friends:
Method | Description |
friends.areFriends | function to match if the two users are friends or not. |
friends.get | function to get a list of ID friend's |
friends.getAppUsers | function to determine whether the user has been authorized in a particular application |
friends.getList | function to display group/friend list |
friends.getMutualFriends | function to get a list of ID mutual friend of both the user matched. |
Knowing the Friend Status
You can find out whether the A and the B is friends with friends.areFriends method. You can just enter user ID A and user ID B. Use the following formula:
1 | $facebook ->api_client->friends_areFriends( $uidA , $uidB ); |
- $uidA = ID user A
- $uidB = ID user B
Friends.areFriends method will produce an array with a structure like the following example:
01 | Array ( [0] => Array ( [uid1] => 500055128 |
02 | [uid2] => 522303217 |
03 | [are_friends] => 0 ) |
04 | [1] => Array ( [uid1] => 500633475 |
05 | [uid2] => 522750967 |
06 | [are_friends] => 0 ) |
07 | [2] => Array ( [uid1] => 503333564 |
08 | [uid2] => 526801479 |
09 | [are_friends] => 0 ) |
10 | [3] => Array ( [uid1] => 530387073 |
11 | [uid2] => 527266170 |
12 | [are_friends] => 0 ) |
13 | [4] => Array ( [uid1] => 503691892 |
14 | [uid2] => 503491166 |
15 | [are_friends] => 1 ) |
16 | ) |
Value 0 means that two users are still not friends, otherwise the value of 1 means the two have been friends.
Here is an example of use (please replace the example ID with the User ID of your friends):
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae8529134daaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7caaaaaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | Check friend relationship:<br> |
17 | <? |
18 |
19 | $users1 = array (500055128,500633475,503333564,530387073,503691892); |
20 | $users2 = array (522303217,522750967,526801479,527266170,503491166); |
21 | $arrstat = array ( 'not friend' , 'friend' ); |
22 | ?> |
23 |
24 | <ul> |
25 | <? |
26 | $check = $facebook ->api_client->friends_areFriends( $users1 , $users2 ); |
27 | echo "<h4>Return from Facebook</h4>" ; |
28 | print_r( $check ); |
29 |
30 | echo "<h4>Check Result</h4>" ; |
31 | for ( $i =0; $i < count ( $check ); $i ++){ |
32 | $uid1 = $check [ $i ][ 'uid1' ]; |
33 | $uid2 = $check [ $i ][ 'uid2' ]; |
34 | $stat = $check [ $i ][ 'are_friends' ]; |
35 | $label = $arrstat [ $stat ]; |
36 | echo "<li><fb:name uid='" . $uid1 . "' useyou=\"false\" /> and <fb:name uid='" . $uid2 . "' useyou=\"false\" /> are " . $label . "</li>" ; |
37 | } |
38 | ?> |
39 | </ul> |
If you run, will produce the following output:
Figure 3.1 Matching the status of friends
Showing Friend List
You can group your friends based on your needs. Example co-workers, teammates, classmates, college friends, and so on. This is called the friend list. Friend list appeared on the front page Facebok you. Please see the left menu page.
Figure 3.2 Friend list
To display the friend list, you can use the formula:
1 | $facebook ->api_client->friends_getLists(); |
Example usage
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae8529134daaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7caaaaaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | Your friend list:<br> |
17 | <? |
18 | $fls = $facebook ->api_client->friends_getLists(); |
19 | ?> |
20 | <? |
21 | echo "<h4>Return array from Facebook</h4>" ; |
22 | print_r( $fls ); |
23 | ?> |
24 | <h4>Check Result</h4> |
25 | <ul> |
26 | <? |
27 | foreach ( $fls as $fl ){ |
28 | echo "<li>" . $fl [ 'name' ]. "</li>" ; |
29 | } |
30 | ?> |
31 | </ul> |
The results as follows:
01 | Return array from Facebook |
02 | Array ( [0] => Array ( [flid] => 70331189444 |
03 | [name] => php ) |
04 | [1] => Array ( [flid] => 67370929444 |
05 | [name] => artis ) |
06 | [2] => Array ( [flid] => 56293594444 |
07 | [name] => kongkow ) |
08 | [3] => Array ( [flid] => 56248104444 |
09 | [name] => sekolah ) |
10 | [4] => Array ( [flid] => 56242989444 |
11 | [name] => dokter ) |
12 | [5] => Array ( [flid] => 56219829444 |
13 | [name] => buku ) |
14 | [6] => Array ( [flid] => 56215709444 |
15 | [name] => politik ) |
16 | ) |
17 | |
18 | Check Result |
19 | php |
20 | artis |
21 | kongkow |
22 | sekolah |
23 | dokter |
24 | buku |
25 | politik |
User of Application
To find users who use your application, you can use friends.getAppUsers method. Formulation as follows:
1 | $facebook ->api_client->friends_getAppUsers(); |
Usage example:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae8529134daaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7caaaaaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | Your friends who are users of this app:<br> |
17 | <? |
18 | $friends = $facebook ->api_client->friends_getAppUsers(); |
19 | ?> |
20 |
21 | <? |
22 | echo "<h4>Return array from Facebook</h4>" ; |
23 | print_r( $friends ); |
24 | ?> |
25 | <h4>Check Result</h4> |
26 | <ul> |
27 | <? |
28 | foreach ( $friends as $friend ){ |
29 | echo "<li><fb:name uid'" . $friend . "' useyou='false' /></li>" ; |
30 | } |
31 | ?> |
32 | </ul> |
Showing Mutual Friends
You can find out who became a friend of the A and the B. This is called mutual friends. Formulation is:
1 | $facebook ->api_client->friends_getMutualFriends( $uid1 , $uid2 ); |
Usage example:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae8529134daaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7caaaaaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | Mutual friends:<br> |
17 | <? |
18 | $uid = 1493017625; |
19 | $friends = $facebook ->api_client->friends_getMutualFriends( $uid ); |
20 | ?> |
21 |
22 | <? |
23 | echo "<h4>Return array from Facebook</h4>" ; |
24 | print_r( $friends ); |
25 | ?> |
26 | <h4>Check Result</h4> |
27 | Your friend is <fb:name uid= '<?=$uid?>' useyou= 'false' /><br> |
28 | Mutual friend:<br> |
29 | <ul> |
30 | <? |
31 | foreach ( $friends as $friend ){ |
32 | echo "<li><fb:name uid='" . $friend . "' useyou='false' /></li>" ; |
33 | } |
34 | ?> |
35 | </ul> |
The result you can see in Figure 3.3:
Figure 3.3 Viewing a mutual friend
Facebook Application Programming Step by step tutorial - part 5. On Facebook, users can keep a list of activities. Thus, the user can also use Facebook to optimize the planning himself. Facility is called Events. Fun anymore, we can invite friends to join the event we have made. Example event page views you can see in Figure 3.4.
In addition to showing users their own activity, Facebook also displays the recommended activities to him.
Facebook allows us to access the event data. That means you can create event-based applications. That's why there are APIs for events. There is some method to the API Events. Here is a list of API Events:
Method | Description |
events.cancel | Cancel an event / activity. Action should be carried out by admin for an event. |
events.create | Creating an event |
events.edit | Editing an existing event |
events.get | Menampilkan semua event berdasarkan filter |
events.getMembers | Showing Membership an event |
events.invite | Inviting the user to an event |
events.rsvp | Setting the arrival options |
Figure 3.4 Display event page
Showing Events
Formula to show the event as follows:
1 | $facebook ->api_client->events_get( $uid , $eids , $start_time , $end_time , $rsvp_status ); |
- $uid is the user ID you want to display eventnya.
- $eids is ID event. Like as a user ID, as well as with the event. Each event has a ID which is usually called $eid.
- $start_time and $end_time is a parameter to filter out events that will be displayed. $start_time means the beginning of time, while $end_time is the final time. Standard time used is UTC date/time value. Do not worry, PHP has a function called time() to convert time in accordance with this method request.
- $rsvp_status is the status of arrival. The value of this status is attending (sure to come), unsure, declined, or not_replied.
Well, let's try this method first. Now run the following programs:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae85291aaaaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd7aaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Event<h2> |
17 | <? |
18 | $events = $facebook ->api_client->events_get(null, null, null, null, null); |
19 |
20 | echo "<h3>Return array from Facebook</h3>" ; |
21 | print_r( $events ); |
22 | ?> |
The result you can see in Figure 3.5. Now we analyze the code above. We write a line of code to display the event as follows:
1 | $events = $facebook ->api_client->events_get(null, null, null, null, null); |
Because we are filled with null parameters, meaning we do not do any filtering. We will display all events. However, although the $eid filled null, it does not mean displaying events for all users. Automatically displayed only event you have (or users who access these pages).
Figure 3.5 Showing event in array format
If we look, the data presented in array consists of:
- eid is the id of the event.
- name is the name or title of the event.
- tagline is an interesting short sentences to attract users to visiting the page event.
- nid is ID maker event.
- pic is the URL of the image that appear in the event. The maximum width of 100px and height 300px.
- pic_big is URL a large image. The maximum width of 200px and height 600px.
- pic_small is a small image. Maximum width 50px and height 150px.
- host is the name of the event creator.
- description is a brief description or explanation of the event.
- event_type is the type of event. To fill it, you just choose a list of types that have been provided by Facebook.
- event_subtype are details of the event type. To fill it, you just choose a list of subtype which has been provided by Facebook.
- start_time is the start time of the event.
- end_time the expiration of the event.
- creator is the ID of the maker.
- update_time is the time to register or to update the event on Facebook.
- location is the place or location of the event took place.
- venue is the details of where the event took place. In the data there are street venue, city, state, and country.
These results, if written in array format will look like the following:
01 | Array ( [0] => Array |
02 | ( [eid] => 191257662149 |
03 | [name] => Obrolan Senja |
04 | [tagline] => Ayo berpartisipasi |
05 | [nid] => 0 |
06 | [pic] => http: //profile.ak.fbcdn.net/object2/11/124/s19277.jpg |
07 | [pic_big] => http: //profile.ak.fbcdn.net/object2/1/124/n19.jpg |
08 | [pic_small] => http: //profile.ak.fbcdn.net/object2/18/14/t162.jpg |
09 | [host] => Faiz Ah |
10 | [description] => Hi..! APA KABAR FIKSI FANTASI? |
11 | [event_type] => |
12 | [event_subtype] => |
13 | [start_time] => 1257463800 |
14 | [end_time] => 1257474600 |
15 | [creator] => 1524500000 |
16 | [update_time] => 1257130015 |
17 | [location] => Rangkas Club, Jl. Sand 101, Yogyakarta |
18 | [venue] => Array ( [street] => |
19 | [city] => |
20 | [state] => |
21 | [country] => ) |
22 | [privacy] => OPEN |
23 | [hide_guest_list] => 0 |
24 | [show_in_search] => 0 |
25 | ) |
Here we will modify the code to be nice appearance:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae85291aaaaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd7aaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Event<h2> |
17 | <? |
18 | $events = $facebook ->api_client->events_get(null, null, null, null, null); |
19 |
20 | //echo "<h3>Return array from Facebook</h3>"; |
21 | //print_r($events); |
22 | ?> |
23 | <table> |
24 | <? |
25 | foreach ( $events as $event ){ |
26 | ?> |
27 | <tr> |
28 | <td colspan= "2" ><?= date ( "l dS F Y" , $event [ 'start_time' ])?></td> |
29 | </tr> |
30 | <tr> |
31 | <td><img src= "<?=$event['pic_small']?>" ></td> |
32 | <td valign= "top" > |
33 | <?= $event [ 'name' ]?> |
34 | <br> |
35 | <?= $event [ 'tagline' ]?> |
36 | <br><br> |
37 | Type: <?= $event [ 'event_type' ]?> - <?= $event [ 'event_subtype' ]?><br> |
38 | Where: <?= $event [ 'location' ]?><br> |
39 | When: <?= date ( "dS F Y h:i" , $event [ 'start_time' ])?> - <?= date ( "dS F Y h:i" , $event [ 'end_time' ])?><br> |
40 | </td> |
41 | </tr> |
42 | <tr> |
43 | <td> </td> |
44 | </tr> |
45 | <? |
46 | } |
47 | ?> |
48 | </table> |
The result:
Figure 3.6 Event Display
Showing Member from Event
To display the member of an event, you can use the following formula:
1 | $facebook ->api_client->events_getMembers( $eid ); |
Following simple example:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae85291aaaaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd7aaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Event<h2> |
17 | <? |
18 | $events = $facebook ->api_client->events_getMembers(141015406075); |
19 |
20 | echo "<h3>Return array from Facebook</h3>" ; |
21 | print_r( $events ); |
22 | ?> |
The output like this:
01 | Array ( [attending] => Array |
02 | ( [0] => 821214608 |
03 | [1] => 1535126550 |
04 | [2] => 1557821758 |
05 | [3] => 1231450659 |
06 | [4] => 857574311 |
07 | [5] => 1649292533 |
08 | [6] => 1613413783 |
09 | [7] => 100000334262668 |
10 | [8] => 1289626293 |
11 | [9] => 1211923468 |
12 | [10] => 770277356 |
13 | ) |
14 | [unsure] => Array |
15 | ( [0] => 1506487084 |
16 | [1] => 1398533601 |
17 | [2] => 1481580815 |
18 | [3] => 1640106742 |
19 | [4] => 1138298482 |
20 | [5] => 1584435287 |
21 | ) |
22 | [declined] => Array |
23 | ( [0] => 1094043520 |
24 | [1] => 1357102927 |
25 | [2] => 100000177951664 |
26 | [3] => 1538477908 |
27 | [4] => 1245755031 |
28 | [5] => 718354339 |
29 | ) |
30 | [not_replied] => |
31 | ) |
To show the name of those ID, you can modify the code like this:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae85291aaaaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd7aaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Event<h2> |
17 | <? |
18 | $events = $facebook ->api_client->events_getMembers(141015406075); |
19 |
20 | echo "<h3>Attending</h3>" ; |
21 |
22 | echo "<ol>" ; |
23 |
24 | if ( $events [ 'attending' ][0]){ |
25 | foreach ( $events [ 'attending' ] as $member ){ |
26 | echo "<li><fb:name uid=\"$member\" useyou=\"false\"></li>" ; |
27 | } |
28 | } else { |
29 | echo "None" ; |
30 | } |
31 |
32 | echo "</ol>" ; |
33 |
34 |
35 | echo "<h3>Unsure</h3>" ; |
36 |
37 | echo "<ol>" ; |
38 |
39 | if ( $events [ 'unsure' ][0]){ |
40 | foreach ( $events [ 'unsure' ] as $member ){ |
41 | echo "<li><fb:name uid=\"$member\" useyou=\"false\"></li>" ; |
42 | } |
43 | } else { |
44 | echo "None" ; |
45 | } |
46 |
47 | echo "</ol>" ; |
48 |
49 | echo "<h3>Declined</h3>" ; |
50 |
51 | echo "<ol>" ; |
52 |
53 | if ( $events [ 'declined' ][0]){ |
54 | foreach ( $events [ 'declined' ] as $member ){ |
55 | echo "<li><fb:name uid=\"$member\" useyou=\"false\"></li>" ; |
56 | } |
57 | } else { |
58 | echo "None" ; |
59 | } |
60 |
61 | echo "</ol>" ; |
62 |
63 | echo "<h3>Not Replied</h3>" ; |
64 |
65 | echo "<ol>" ; |
66 |
67 | if ( $events [ 'not_replied' ][0]){ |
68 | foreach ( $events [ 'not_replied' ] as $member ){ |
69 | echo "<li><fb:name uid=\"$member\" useyou=\"false\"></li>" ; |
70 | } |
71 | } else { |
72 | echo "None" ; |
73 | } |
74 |
75 | echo "</ol>" ; |
76 | ?> |
The output like this:
Figure 3.7 List of event's member and their status
To be continued... ^^!
Facebook Application Programming Step by step tutorial - part 6
Facebook users can gather in a group based on their needs. Group is a network of Facebook users based on interest in certain things.
Method | Description |
groups.get | Showing all groups based on the filter |
groups.getMembers | Retrieve membership of a group |
Showing Groups
To display the group, you can use the following formula:
1 | $facebook ->api_client->groups_get( $uid , $gids ); |
- $uid is parameter to get the group to a specific user
- $gids is parameter that contains an array of ID Group. This is optional
The method will return an array with values such as gid, name, nid, description, group_type, group_subtype, recent_news, pic, pic_big, pic_small, creator, update_time, office, website, and venue.
Here is an example of using groups.get without mentioning a specific user ID.
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae8529134aaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd797aaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Groups<h2> |
17 |
18 | <? |
19 | $uid = null; |
20 | $gids = null; |
21 | $groups = $facebook ->api_client->groups_get( $uid , $gids ); |
22 |
23 | echo "<h3>Array Output</h3>" ; |
24 | echo "<pre>" ; |
25 | print_r( $groups ); |
26 | echo "</pre>" ; |
27 |
28 | echo "<h3>Another Output</h3>" ; |
29 | echo "<ol>" ; |
30 | foreach ( $groups as $group ){ |
31 | echo "<li>" . $group [ 'name' ]. "</li>" ; |
32 | } |
33 | echo "</ol>" ; |
34 | ?> |
Example array result as follows:
01 | [15] => Array |
02 | ( |
03 | [gid] => 63623209704 |
04 | [name] => Klub Baca Navila |
05 | [nid] => 0 |
06 | [pic_small] => http: //profile.ak.fbcdn.net/object3/1639/7/t63623209704_322.jpg |
07 | [pic_big] => http: //profile.ak.fbcdn.net/object3/1639/7/n63623209704_322.jpg |
08 | [pic] => http: //profile.ak.fbcdn.net/object3/1639/7/s63623209704_322.jpg |
09 | [description] => Peminat karya sastra terjemahan, sastra pesantren, sastra lokal. |
10 | [group_type] => Common Interest |
11 | [group_subtype] => Languages |
12 | [recent_news] => Navila selalu konsisten menerbitkan karya-karya sastra dari negeri-negeri Timur |
13 | [creator] => 1395458939 |
14 | [update_time] => 1249973079 |
15 | [office] => Pakel Mulyo UH V no 411 |
16 | [website] => http: //klubbacanavila.blogspot.com/ |
17 | [venue] => Array |
18 | ( |
19 | [street] => Pandeyan |
20 | [city] => Jogjakarta |
21 | [state] => Yogyakarta |
22 | [country] => Indonesia |
23 | [latitude] => -7.8 |
24 | [longitude] => 110.367 |
25 | ) |
26 |
27 | [privacy] => OPEN |
28 | ) |
29 |
30 | [16] => Array |
31 | ( |
32 | [gid] => 70358229888 |
33 | [name] => PENULIS PEMULA |
34 | [nid] => 0 |
35 | [pic_small] => http: //profile.ak.fbcdn.net/object3/150/30/t70358229888_169.jpg |
36 | [pic_big] => http: //profile.ak.fbcdn.net/object3/150/30/n70358229888_169.jpg |
37 | [pic] => http: //profile.ak.fbcdn.net/object3/150/30/s70358229888_169.jpg |
38 | [description] => PENULIS PEMULA merupakan komunitas cair, imajiner, yang dibentuk untuk mempertemukan potensi-potensi penulis dari beragam latarbelakang. Diharapkan, PENULIS PEMULA bisa menjadi sekolah bersama bagi yang ingin mendalami soal tulis-menulis. Komunitas ini tidak membatasi diri pada usia, afiliasi politik, agama, genre tulisan, pendidikan, suku, dan sebagainya. Semua berhak menulis! Di sini, mari tuangkan ketegangan kreatif kita! Saling berbagi, dan saling menimba. Di sini, Anda bisa menjadi pemburu naskah, atau naskah Anda yang diburu Salam. |
39 | [group_type] => Student Groups |
40 | [group_subtype] => Creative Arts Groups |
41 | [recent_news] => |
42 | [creator] => 1236819023 |
43 | [update_time] => 1237580951 |
44 | [office] => Perum Bale Asri Blok Q-7 Gamping |
45 | [website] => |
46 | [venue] => Array |
47 | ( |
48 | [street] => Jl Wates Km 9 |
49 | ) |
50 |
51 | [privacy] => OPEN |
52 | ) |
53 |
54 | [17] => Array |
55 | ( |
56 | [gid] => 51735947828 |
57 | [name] => Virtual Intelligent Services International |
58 | [nid] => 0 |
59 | [pic_small] => http: //profile.ak.fbcdn.net/object3/664/105/t51735947828_196.jpg |
60 | [pic_big] => http: //profile.ak.fbcdn.net/object3/664/105/n51735947828_196.jpg |
61 | [pic] => http: //profile.ak.fbcdn.net/object3/664/105/s51735947828_196.jpg |
62 | [description] => Information technology company based on Jakarta and Yogyakarta. |
63 | [group_type] => Business |
64 | [group_subtype] => Companies |
65 | [recent_news] => |
66 | [creator] => 1082022764 |
67 | [update_time] => 1238220998 |
68 | [office] => |
69 | [website] => http: //www.visi.co.id |
70 | [venue] => Array |
71 | ( |
72 | [street] => |
73 | ) |
74 |
75 | [privacy] => CLOSED |
76 | ) |
Figure 3.8 List of group
Showing Member Information
You can see anyone who becomes a member of a group. Formula to see is:
1 | $facebook ->api_client->groups_getMembers( $gid ); |
Please enter your id of the group. The result, you will get an array of user ID that the member group. You will also receive membership status information.
Here's an example usage:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae8529134aaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd797aaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Group Members<h2> |
17 |
18 | <? |
19 | $gid = 80002146608; |
20 | $members = $facebook ->api_client->groups_getMembers( $gid ); |
21 |
22 | echo "<h3>Array Output</h3>" ; |
23 | echo "<pre>" ; |
24 | print_r( $members ); |
25 | echo "</pre>" ; |
26 |
27 | echo "<h3>Another Output</h3>" ; |
28 | echo "<ol>" ; |
29 | foreach ( $members as $member ){ |
30 | echo "<li>" . $group [ 'name' ]. "</li>" ; |
31 | } |
32 | echo "</ol>" ; |
33 | ?> |
The result like this:
01 | Array |
02 | ( |
03 | [members] => Array |
04 | ( |
05 | [0] => 1564394223 |
06 | [1] => 1078527089 |
07 | [2] => 1108567959 |
08 | [3] => 1455886398 |
09 | [4] => 1184927288 |
10 | [5] => 1358360770 |
11 | [6] => 1075642572 |
12 | [7] => 1626207382 |
13 | [8] => 1226868856 |
14 | [9] => 700144751 |
15 | [10] => 1651427457 |
16 | ) |
17 |
18 | [admins] => Array |
19 | ( |
20 | [0] => 1225924230 |
21 | ) |
22 |
23 | [not_replied] => |
24 | ) |
We can modify it to be as follows:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae8529134aaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd797aaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Group Members<h2> |
17 |
18 | <? |
19 | $uid = null; |
20 | $gid = 80002146608; |
21 | $groups = $facebook ->api_client->groups_get( $uid , $gid ); |
22 | $members = $facebook ->api_client->groups_getMembers( $gid ); |
23 |
24 | echo "<h3>Members of " . $groups [0][ 'name' ]. "</h3>" ; |
25 |
26 | echo "<h4>Members</h4>" ; |
27 | echo "<ol>" ; |
28 | foreach ( $members [ 'members' ] as $member ){ |
29 | echo "<li><fb:name uid=\"$member\" useyou=\"false\"></li>" ; |
30 | } |
31 | echo "</ol>" ; |
32 |
33 | echo "<h4>Admin</h4>" ; |
34 | echo "<ol>" ; |
35 | foreach ( $members [ 'admins' ] as $member ){ |
36 | echo "<li><fb:name uid=\"$member\" useyou=\"false\"></li>" ; |
37 | } |
38 | echo "</ol>" ; |
39 |
40 | ?> |
Figure 3.9 List of group's member
Facebook Application Programming Step by step tutorial - part 7. Pages on Facebook can use to display your business information. Page can also be used to display the brand, promoting a band, or your product. The users on Facebook can become fans of the page.
APIs are available for Page is:
Method | Description |
pages.getInfo | Displaying all pages based on the filter |
pages.isAdmin | Checking whether the user is admin page |
pages.isAppAdded | Checking whether the applications have been added |
pages.isFan | Check whether the user is a fan |
Showing Page Information
To display information Facebook Page, you can use the formula:
1 | $facebook ->api_client->pages_getInfo( $pids , $fields , $uid , $type ); |
- $pids is an array of ID page that you want to know the information.
- $fields is an array containing the fields that you want to know.
- $uid is the user ID. You use it to call a specific page based on the user.
- $type is the type of page.
The example usage as follow:
01 | <?php |
02 | // Get these from http://developers.facebook.com |
03 | $api_key = '2c73ae85291aaaaaaaaaaaaaaaaaaaaa' ; |
04 | $secret = '3c041a7cbd7aaaaaaaaaaaaaaaaaaaaa' ; |
05 |
06 | include_once './facebook-platform/php/facebook.php' ; |
07 |
08 | $facebook = new Facebook( $api_key , $secret ); |
09 | $user = $facebook ->require_login(); |
10 |
11 | ?> |
12 | <h1>Yummie Tester</h1> |
13 | Hello <fb:name uid= '<?php echo $user; ?>' useyou= 'false' possessive= 'true' />! <br> |
14 | Your id : <?php echo $user ; ?>.<br> |
15 |
16 | <h2>Page Info<h2> |
17 |
18 | <? |
19 | $pages = $facebook ->api_client->pages_getInfo(null, array ( 'page_id' , 'name' ), $user , null); |
20 |
21 | echo "<pre>" ; |
22 | print_r( $pages ); |
23 | echo "</pre>" ; |
24 | ?> |
The result like this:
01 | Array |
02 | ( |
03 | [0] => Array |
04 | ( |
05 | [page_id] => 19292868552 |
06 | [name] => Facebook Platform |
07 | ) |
08 |
09 | [1] => Array |
10 | ( |
11 | [page_id] => 8810356148 |
12 | [name] => Elex Media |
13 | ) |
14 |
15 | [2] => Array |
16 | ( |
17 | [page_id] => 6358087478 |
18 | [name] => PHP |
19 | ) |
20 |
21 | [3] => Array |
22 | ( |
23 | [page_id] => 89586844253 |
24 | [name] => Rumah Zakat Indonesia |
25 | ) |
26 |
27 | [4] => Array |
28 | ( |
29 | [page_id] => 31920412557 |
30 | [name] => Chemical Engineering Gadjah Mada University |
31 | ) |
32 |
33 | [5] => Array |
34 | ( |
35 | [page_id] => 53812400307 |
36 | [name] => Sri Sultan HB-X Comic Series |
37 | ) |
38 |
39 | [6] => Array |
40 | ( |
41 | [page_id] => 26378422369 |
42 | [name] => GIGI |
43 | ) |
44 |
45 | ) |
In these exercises, we show page_id and name of the page. The information that we can display on your page is:
- page_id the ID of a page.
- name is the name or title of the page.
- page_url is the URL address of a page.
- pic_small profile page is a picture with a maximum size of 50px width and height of 150px.
- pic_square is the URL address of the profile picture box with a width of 50px and height 150px.
- pic_big is the image profile with a maximum size of 200px wide and 600px high.
- pic is the address of the profile picture. The maximum width of 100px and 300px maximum height.
- pic_large is the URL address of the image profile with a maximum width of maximum 396px and 1188px high.
- type is the type of page.
- website is the website address of the page.
- location is the location information / address (eg your office address). This information contains 5 items: street, city, state, country, and zip.
- hour is the operational hours. This information contains mon_1_open, mon_1_close, tue_1_open, tue_1_close, wed_1_open, wed_1_close, thu_1_open, thu_1_close, fri_1_open, fri_1_close, sat_1_open, sat_1_close, sun_1_open, sun_1_close, mon_2_open, mon_2_close, tue_2_open, tue_2_close, wed_2_open, wed_2_close, thu_2_open, thu_2_close, fri_2_open, fri_2_close , sat_2_open, sat_2_close, sun_2_open, sun_2_close.
- band_members is a member of the band.
- bio is information about the biography.
- hometown is the basis of location information.
- genre is the musical flow of information.
- record_label is a record label info.
- founded the information when the company was founded.
- company_overview is brief information about the company is established.
- mission is information about the company's mission.
- products are information products company.
- release_date is the date the information out of a movie.
- starring the information about who starred in the film.
- written_by is information scenario writer TV / Film.
- directed_by is director of the TV / film.
- produced_by was a producer of the TV / film.
- studio is the studio that produced the film.
- awards are awards received.
- plot_outline the plot of the film.
- network is a television network information.
- schedule is a schedule of television shows.
Checking Application
You can check whether your application has been added on the page or not with the formula:
1 | $facebook ->api_client->pages_isAppAdded( $pid ) |
Parameter $pid is the ID of a page. the above formula will yield the value 0 (false) or 1 (true).
Getting status user information
You can check whether the user is connecting to the admin or a fan of a page. Formula that can be used are:
1 | $facebook ->api_client->pages_isFan( $pid ) |
2 | $facebook ->api_client->pages_isAdmin( $pid ) |
Parameter $pid is the ID of a page. Above formula will return the value 1 (true) or 0 (false).
Facebook Application Programming Step by step tutorial - part 8. In each exercise, you have to use the API users. Method you've used is getLoggedInUser. There are several methods you can use associated with user information. Yes, Facebook provides the API for you to access user data from applications you make.
The following methods are available for API Users:
Method | Description |
users.getInfo | Returns information about the user in an array format |
users.getLoggedInUser | Getting a user ID associated with the current session |
users.getStandardInfo | Retrieve the user-specific information in an array format |
users.hasAppPermission | Checking permissions on the application |
users.isAppUser | Checking whether the user is entitled to call the application |
users.setStatus | Updating user status |
Getting User Information
You can obtain user profile information. Formulation as follows:
$facebook->api_client->users_getInfo($uids, $fields);
Parameter $uids is ID users in an array format. $Fields parameter contains an array of fields you want to know. Here is the full table field that you can access:
Element | Description | Child Element |
uid | ID User | |
about_me | about me field, overview about user | |
activities | user activities at profile | |
affiliations | user network affiliations | year, type ['college', 'high school', 'work', 'region'], status, name, and nid |
birthday | user birthday | |
books | favorite books | |
current_location | Current user location | city, state, country, zip |
education_ history | user education information | education_info, children: name, year, concentration |
first_name | ||
has_added_app | checking whether user has added calling application | |
hometown_location | city, state, country, zip | |
hs_info | high school information | hs1_name, hs2_name, grad_year, hs1_key, hs2_key |
interests | ||
is_app_user | checking whether user has used application | |
last_name | ||
meeting_for | list of desired relationship (blank, friendship, A relationship, dating, random play, whatever I get) | |
meeting_sex | list of desired genders corresponding to the interested in profile element | |
movies | favorite movies | |
music | favorite music | |
name | name of user | |
notes_count | total number of notes written by user | |
pic | URL of user profile picture (max. 100 X 300px) | |
pic_big | URL of user profile picture (max. 200 X 600px) | |
pic_small | URL of user profile picture (max. 50 X 150px) | |
pic_square | URL of square picture (max. 50 X 50px) | |
political | Political view(blank, Very Liberal,Liberal, Liberal, Moderate, Conservative, Very conservative, apathetic, libertarian, other) | |
profile_update_time | time that the user's profile was last updated | |
quotes | favorite quotes | |
relationship_status | relationship status (blank, single, in a relationship, in an open relationship, engaged, married, it's complicated) | |
religion | Religion views | |
sex | sex | |
significant_other_id | user ID of the person the user is in relationship with | |
status | Status message | |
timezone | offset from GMT | |
tv | favorite tv shows | |
wall_count | total number of posts to the user's wall | |
work_history | list of work_info elements |
Examples of its use as follows:
<?php // Get these from http://developers.facebook.com $api_key = '2c73ae8529134daaaaaaaaaaaaaaaaaa'; $secret = '3c041a7cbd7970aaaaaaaaaaaaaaaaaa'; include_once './facebook-platform/php/facebook.php'; $facebook = new Facebook($api_key, $secret); $user = $facebook->require_login(); ?> <h1>Yummie Tester</h1> Hello <fb:name uid='<?php echo $user; ?>' useyou='false' possessive='true' />! <br> Your id : <?php echo $user; ?>.<br> <h2>User Info<h2> <? $wanted_info = array('first_name', 'last_name', 'birthday', 'sex' ,'education_history' , 'work_history'); $profiles = $facebook->api_client->users_getInfo($user, $wanted_info); echo "<pre>"; print_r($profiles); echo "</pre>"; ?>
The result is like this:
Array ( [0] => Array ( [birthday] => February 2 [education_history] => Array ( [0] => Array ( [name] => Gadjah Mada University [year] => 1993 [concentrations] => Array ( [0] => Chemical Engineering ) [degree] => ) ) [first_name] => Wiwit [last_name] => Siswoutomo [sex] => [uid] => 596119444 [work_history] => ) )
You can combine with another method, such as the following example:
<?php // Get these from http://developers.facebook.com $api_key = '2c73ae8529134daaaaaaaaaaaaaaaaaa'; $secret = '3c041a7cbd7970aaaaaaaaaaaaaaaaaa'; include_once './facebook-platform/php/facebook.php'; $facebook = new Facebook($api_key, $secret); $user = $facebook->require_login(); ?> <h1>Yummie Tester</h1> Hello <fb:name uid='<?php echo $user; ?>' useyou='false' possessive='true' />! <br> Your id : <?php echo $user; ?>.<br> <h2>Friends Info<h2> <? $friends = $facebook->api_client->friends_get(); $wanted_info = array('first_name', 'last_name', 'status'); $profiles = $facebook->api_client->users_getInfo($friends, $wanted_info); echo "<ul>"; foreach($profiles as $profile){ $firstname = $profile['first_name']; $lastname = $profile['last_name']; $status = $profile['status']['message']; if($status){ echo "<li>$firstname $lastname : $status</li>"; } } echo "</ul>"; ?>