Start learning with our library of video tutorials taught by experts. Get started

Building Facebook Applications with PHP and MySQL

Integrating a query into an application


From:

Building Facebook Applications with PHP and MySQL

with Ray Villalobos

Video: Integrating a query into an application

Integrating FQL queries into your application is pretty similar to feeding paths to the API method. Let's take a look at some of the differences in a very simple example. So I have a document that looks pretty much like the examples we've been using, it requests a Facebook object with your appID and secret, than checks to see if the user is logged in and creates a logout and login URL. Now, if you remember from the chapter on accessing Open Graph data, this page in the Facebook PHP documentation has instructions for creating paths.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
Building Facebook Applications with PHP and MySQL
1h 45m Intermediate Jan 16, 2013

Viewers: in countries Watching now:

Learn the basics of building complex, data-driven applications with the Facebook PHP SDK and MySQL. Author Ray Villalobos first introduces the fundamentals, such as checking to see if a user is logged into an application, accessing Facebook user data through the Open Graph API, and making complex API calls with the Graph API Explorer. The course then dives into building an application with API paths and Facebook Query Language (FQL) calls. Along the way, you'll discover how to post to a user's wall, upload photos, integrate with webpages, and more.

Topics include:
  • Downloading and installing the PHP SDK
  • Logging in and authenticating users
  • Accessing Open Graph data
  • Working with connection subpaths, limits, and subsearches
  • Styling a Facebook app with CSS
  • Setting up pagination
  • Understanding Facebook Query Language (FQL)
  • Integrating query results into a full-scale application
Subjects:
Developer Web Databases Web Development
Software:
Facebook MySQL PHP
Author:
Ray Villalobos

Integrating a query into an application

Integrating FQL queries into your application is pretty similar to feeding paths to the API method. Let's take a look at some of the differences in a very simple example. So I have a document that looks pretty much like the examples we've been using, it requests a Facebook object with your appID and secret, than checks to see if the user is logged in and creates a logout and login URL. Now, if you remember from the chapter on accessing Open Graph data, this page in the Facebook PHP documentation has instructions for creating paths.

If you scroll all the way to the bottom and then come up a little bit, you can see that we pass a path to the Facebook API object and optionally a method. This is how you make FQL calls, you simply add a method variable with the value fql.query to the array we send to the API method, plus the query that you want. So let's take a look at how this is going to work on a simple example. I'm going to create a call to the Graph API called $moviefriends_graph. This is going to be fed an array with a couple of variables.

One is going to be the method fql.query and the other one is going to be our query, and I'm going to want double quotes instead of single quotes here, because some of thing I'm going to pass will include single quotes. So let me delete this comma and just delete that right there, and now we're ready to insert the query that we want. I've already prepared this query on the Graph API Explorer. This query returns the name, user ID, the movies, and a picture from our friends.

You may notice that the movies information that we get doesn't look like what we got when we did a path to query movies, it's just a list of the movies, not the user ID and the picture, and all the information we had. And that's one of the issues with FQL, you don't always get the same data, and you more than likely don't get the richness of the information coming back as you did with the Graph API. So let me go ahead and copy this query, and I'm going to switch back and paste that query right here. So I was using double quotes because this query includes a check to see if the movies field is empty, and in there I use single quotes, so this just makes it easier since the single quotes of my query right here will not get confused with these single quotes.

So now that we got this, let's just go ahead and print out the path on the browser so we can see what it looks like. Let me go Save this, and I'll switch back over here, and I'll go to my application, and I'm going to make sure I type in the name of my page, which is fqlquery.php at the end of the normal path to my application. So let me Refresh that page, and now we can see the data that we get back. Now, notice that there's a slight difference between what we're seeing here and what you see on the Graph API Explorer.

When you query with the Graph API Explorer, you get an item called data. When we get the results from doing the PHP SQL query, we do not get an item called data. So you have to remember to not include that, like you did when we query it with paths. Now that we know that, we can print out just a list of images. So we'll do a foreach statement, and we'll pass it the $moviefriends_graph. Now, in previous movies we included data as the object that we passed to this foreach statement, but we don't need to do that here because the FQL query doesn't return that, and all we have to do is just output the image.

So let me go ahead and Save that, and I'll go back into my application and Refresh this page, and we just see a little grid of images right here. Let me go back and get rid of the printout of our object. So I'll Save this, come back here, Refresh this page, and now you see the grid of images. Now, the cool thing about this list is that it's only the list of friends that have recommended movies. So working with FQL is pretty similar to using paths with the Graph API. I'm not sure if you can tell, but you might notice that FQL calls tend to be a little bit slower than regular path calls.

However, it was very easy for us to get only the list of users with movies, which was a problem with our previous application. It does let you perform some queries that you couldn't otherwise, so sometimes you have to make tradeoffs between speed and functionality when choosing whether to use paths or FQL.

There are currently no FAQs about Building Facebook Applications with PHP and MySQL.

Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Building Facebook Applications with PHP and MySQL.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked