Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Integrating a query into an application

From: Building Facebook Applications with PHP and MySQL

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.

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.

Show transcript

This video is part of

Image for Building Facebook Applications with PHP and MySQL
Building Facebook Applications with PHP and MySQL

24 video lessons · 8309 viewers

Ray Villalobos
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

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.


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.

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
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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.