Facebook API – Part 4

| 25. March 2013 | 1 Comment

In the last article of Facebook API I show you more about the PHP SDK.

Initialization

Like the JavaScript SDK, the first thing for the PHP SDK is also to initialize the SDK. So we need to create a new Facebook object. This object needs two things, the app id and the app secret.

Get data from Facebook

After initialization we can request data from Facebook for the logged in user. The following line of code gets an array with all information that is available for the user. If you are not logged in, you will get an empty array:

FQL

FQL is a language which looks like the SQL language and is needed to get information from Facebook. With SQL like statements you can make detailed requests. The above example would look like the following with FQL:

For this we have to decide which columns we want to get returned. So we only want the name and the username for the logged in user. This also works for friends of the user. For all other users on Facebook this does not work, if they set the name or username not to display to public.

The last thing I want to show is a more complex example, where I get the id of the sender and the id of the recipient of an app request. These app requests can be sent from users to other users to invite them to an app.

Part 1 | Part 2 | Part 3

Category: Allgemein

Comments (1)

Trackback URL | Comments RSS Feed

  1. Usman Ehtesham Gul says:

    Hello, I followed your exact instructions to use FQL with Graph API but when i log out and log in again, i get the following error:

    Fatal error: Uncaught Exception: Requires user session

    I am already logged in with facebook. API call to $user_profile = $facebook->api(‘me’,’GET’); work. But i get this exception when i try to run an FQL query. Would really appreciate some help in this. Hope to hear from you soon. :)

Leave a Reply

Your email address will not be published. Required fields are marked *