HomePHP Page 2 - Facebook PHP API Applications: A Second Look
Understanding the Facebook Graph API - PHP
This is the second part of the Facebook PHP API tutorial. The first part ran on August 11. It covered the most basic features, such as adding the basic Facebook “Like” button, the “Recommendations” plugin and registering your applications in Facebook to get an Application ID and Secret key. In this part, we'll delve deeper.
According to Facebook, every object in the social graph contains a unique ID. So all Facebook users have a unique ID assigned to them.
Another thing you need to know is that you can access a Facebook user's information via the graph URL; you just need to append the Facebook user's ID. For example:
where "ID" is the actual user ID. The data are presented as JSON objects. For example, if your user ID is 747166266, you can access it in the address bar as follows:
See the screen shot below:
The required get_facebook_cookie_function
This is the start of the PHP script discussion. We're going to analyze the sample script provided by the Facebook API. The first step is to get the Facebook cookie. This is will be used by the succeeding scripts to check whether or not the user has logged in to your website using their Facebook account.
To do this in your PHP web application, paste the following code at the top of your PHP scripts (the very first line of code):