Before using any call from Facebook Graph API, be sure that you made correct initialization. Look at tutorial for Graph API Initialization. Getting of data using the Graph API is made by calling 'api' method on Facebook object. Following example show how to get object of logged user.
$loggedUser = $facebook->api('/me');
Every Facebook object can be get by entering its unique identification. It can be a number or unique name. For example, user object can be get by unique number or by first and last name connected with '.' character.
$person1 = $facebook->api('/jessica.alba');
$person1_2 = $facebook->api('/298334973652');
Properties
To get properties from object returned by Graph API, the simplest way is to get array element by its key. For example, for user object the key can be 'name' or 'id'. Here is an example of getting basic user data from 'person1' object:
$personId = $loggedUser['id']; $personFistName = $person1['first_name']; $personLastName $person1['last_name']; $personGender = $person1['gender']; $personBirthday = $person1['birthday'];
Connections
Every Facebook object can be connected with numerous objects of the same and different types. For example Facebook user can have as connections his friends or products he likes. Here is an example of getting a list of logged user friends and printing names of the friends:
$friends = $facebook->api('/me/friends');
$friendsData = $friends['data'];
for ($i = 0; $i < sizeof($friendsData); $i++)
{
$friend = $friendsData[$i];
echo $friend['name'] . ", ";
}
As it can be seen, every connection can be get by calling 'api' method of Facebook object and providing a path contained of Facebook object Identicator, plus name of connection type, connected with slash character.




