New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

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

Building Facebook Applications with PHP and MySQL
Illustration by

Implementing a path on a page


From:

Building Facebook Applications with PHP and MySQL

with Ray Villalobos

Video: Implementing a path on a page

We've been learning a lot about paths and how to use the Graph API Explorer. Let's take a look at how we can integrate a simple path in an application and how to work with photos. We'll start off with the document we made in the movie understanding Graph API paths. I'll start by changing the title, and I'm going to add a line to link this file to a CSS document I'll create later. I'm also going to delete the line printing the user's ID. Now let's delete the part where we print out the user's information, and we'll start our output by creating a new list group.

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

Implementing a path on a page

We've been learning a lot about paths and how to use the Graph API Explorer. Let's take a look at how we can integrate a simple path in an application and how to work with photos. We'll start off with the document we made in the movie understanding Graph API paths. I'll start by changing the title, and I'm going to add a line to link this file to a CSS document I'll create later. I'm also going to delete the line printing the user's ID. Now let's delete the part where we print out the user's information, and we'll start our output by creating a new list group.

We've added an lgrid for left grid and a group class so we can style these later. Now we need to iterate through each piece of data. Let's go over to the Graph API Explorer, and I'm going to modify this path by adding /friends to the end of the default path. This is going to give me this user's current list of friends. I can also use /me as the path, which is what I do on the application. This path is returning the name of the friend, as well as an ID. Let's go through each friend by using the foreach statement.

Now I'm passing along this data field right here, because if we look at the Open Graph API Explorer, this object returns an array of data. Now let's create the code for putting the user's data inside a list. And now we're ready to output an image. You don't have to do this from the Open Graph. Default images of objects are public, so the easiest way to get an image is to create an img tag calling the Graph API, then adding the ID, plus the /picture path afterwards.

So I need to make sure I add the friends path into the API call. Then I'll switch over to my app and refresh, and I just see the list of photos come up. You may notice that the app is no longer printing the user's name right next to the word Hello. When you change the paths so that it points to /me/friends, you lose access to the first name of the user, since now the data from Facebook shows only your friends info. It's not a big deal, since what we are most interested in is experimenting with friends' data.

If your server is set to show notices, you may want to delete line 22 printing Hello to the screen. Now these photos aren't clickable to the user's profile, so let's go ahead and add that. To get the URL of the current object, you simply type in facebook.com/the ID number of the object. You want to make sure you use _top as the target so that the browser doesn't try to load the page into the canvas's iFrame. So we'll save this and go back into our application, we'll refresh the browser, and now these icons should be clickable to each user's account.

It'd also be nice to have the user's name under each photo. So let's go ahead and add that. So I'm going to go ahead and save this, and I'll switch over to the browser, refresh, and now the name is underneath each user. This could look a lot better so I'm going to go ahead and add some CSS. I'm going to create a new CSS file, I am using transmit as my FTP Application. So I'm going to right-click, select New File make sure you same name that I used earlier when I created my link to my style sheet, and I'll right-click and select Open With > Espresso, which is my editor.

It opens open in a new window, but I can just click and drag it right here to enter it as a new tab. So this is a list, I need to start by addressing that when you float list item tags, the Container loses track of the height of its content. This is known as a Clear Fix, but I like to use the word Group, instead of Clear Fix. I've created a gist with the code you need, so you can just copy and paste from right here. And I'll paste that into my CSS file. If you want to learn more about working with Floats and the Clear Fix technique, check out CSS page layouts in the online training library.

So now let's create a style for the body tag making sure that we establish some defaults for our document. And now we'll add three simple styles to make our grid of photos look better. So let's go ahead and save this, and we'll go back to our project and refresh. And you can see our grid looks a lot better. So applying paths in your projects takes a little bit more set up, but it's pretty easy, and you work with the foreach command to iterate through each of the different elements returned by the Open Graph API.

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

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

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.