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

Working with connection subpaths, limits, and subsearches

From: Building Facebook Applications with PHP and MySQL

Video: Working with connection subpaths, limits, and subsearches

The Graph API allows you to search through a user's graph data by creating a path to a user's account, but you can also use sub paths to look through a user's connection. You can build more complicated queries by using limits and also making sub queries. Let's take a look at what it takes to make a really complex connection to the Open Graph. So, I have the Open Graph API Explorer already open and by default it's creating a path for me with this user's ID, as well as calling two fields ID and Name. In your apps, you're probably going to be using the path /me to get the graph of the current user, you can do that in here too. You can also of course use the ID of any object.

Working with connection subpaths, limits, and subsearches

The Graph API allows you to search through a user's graph data by creating a path to a user's account, but you can also use sub paths to look through a user's connection. You can build more complicated queries by using limits and also making sub queries. Let's take a look at what it takes to make a really complex connection to the Open Graph. So, I have the Open Graph API Explorer already open and by default it's creating a path for me with this user's ID, as well as calling two fields ID and Name. In your apps, you're probably going to be using the path /me to get the graph of the current user, you can do that in here too. You can also of course use the ID of any object.

If you want to find out about connections, then you've got a couple of options, you can click on the plus sign and choose a connection. At first you'll see this field section, if you scroll down you'll see connections, let's go ahead and pick friends, and I'll hit Submit, and I'll get a list of the user's friends. You can also see that friend was added to the list of fields in the path. The second way to do this is by just adding /friends as part of the path to get directly to a user's friends.

Sometimes it's a little bit cleaner to have access to specific connections, like with the previous path, the Graph API is going to return the name, as well as an ID for each user. We can request additional fields if you like, so let's add movies from the list of connections, and I'll hit Submit. Notice that the Graph API sometimes returns more things then you're asking for, so for example, when we request that movies, it's also returning category as well as the created time, you can limit the amount of results by adding a limit field.

From this pop-up list, I'll select limit, and type in a number, say 3. This is going to limit not the amount of movies, but the amount of friends that are being listed. So here you have one friend, another friend, and another friend. To display additional results, you can also use the offset variable, I can just type that one in, that's going to allow me to see the next three users. This will allow you to create additional pages of results in your applications.

Let's say that now instead of limiting the amount of friends, you wanted to limit the amount of movies each friend has shared with you, you could do that by adding the limit command to the movies field. Notice that there is a plus sign inside of the movies field, so if I click on that and select limit, I can type in a limit for the amount of movies that I want each result to generate, so I'll select 2, hit Submit, and now I'm only getting two movies right here. Notice that some of these friends haven't recommended any movies, but they still appear as part of this query.

Let's go ahead and add the name of the friends so it's a little clear. So you can see the user Cecilia Largo hasn't recommended any movies. Now within the movies you also have access to subfields, if you click on this plus sign you can see that the fields are now different than they used to be. They have things like awards, directed_by, name, plot_outline, and other things. Let's go ahead and add some subfields to the movies. You can choose them from this pop-up list or if you know him just type them in.

Take a look at what it's doing here, it's adding dots to the movies and adding additional commands. One of the commands is limit(2) and the other one is fields and in there I can type in the additional fields I want, and I'll hit Submit. So now I can see the movies ID, as well as the name, a link to a picture, as well as a link to the page that the user had liked to get this in their profile. I also added a description and a number of likes that tells you how popular this movie is based on how many people have liked this page.

These parentheses also let you go inside individual fields and pass additional attributes. Take, for example, the image we get back, we asked for an image link, and it's given us a URL right here. We can pass some parameters requesting that the image be a certain size. Now I'm going to hold down the Command key and click on this image, so it'll appear in a new tab. So when I click on that, you'll see that we requested a 100x100 pixel image, and it tries as best as it can to give you an image of that size.

If somebody has uploaded a smaller image, it'll just give you whatever image you have. So you may have to develop some CSS just scale up or down any images that are too big too small, it's a good idea to include a width and a height parameter just to make sure we limit the pictures to the size that we want. By default, some pictures will be a certain width, and whatever height the user use, to upload the image. So you can see that by adding some periods and parentheses, we can really get very detailed in how we construct the path. They can get quite complex, but they're pretty much like passing a string via a get command on a form.

Once you get the hang of the syntax, you can perform some pretty complex queries into the open Graph API.

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