- Testing FQL Queries
- Finding the User's Friends
- Finding the User's Links
- Executing the FQL Queries
- Putting It All Together
- Summary
Finding the User's Links
Retrieving the links published by the current user is trivial compared to the efforts we invested into the previous query: Just fetch data from the link table based on the link's owner (the current user's ID). The fields we'll need are the link's title and URL, so the initial FQL query should look similar to this one:
SELECT url,title FROM link WHERE owner = current-user
As you might anticipate by now, the query returns the required data, but not exactly in the format expected from the documentation. Links to external destinations contain the information we've come to expect, as in the following JSON-formatted sample row:
{"title":"10 amazing truths you already suspected", "url":"http:\/\/http://www.sfgate.com\/cgi-bin\/article.cgi?f=\/g\/a\/2009\/08\/07\/notes080709.DTL"}
However, the links to other pages within Facebook contain unexpected amounts of information:
{"title":"Wall Photos", "url":{ "album":{"aid":54500,"fbid":45708389495,"user":669379495, "created":1232703214,"modified":1250598722, "name":"Wall Photos","description":"","visible":1, "network_keys":"0","cover_pid":1202011,"cover_link":4571, "size":12,"location":"","type":8,"source":0, "creator_id":669379495,"modified_major":1250598722, "href":"http:\/\/api.facebook.com\/album.php ..."}, "title":"Wall Photos", "owner_id":"669379495", ...}}
To display just a few links published by the user, we can limit the result set with the LIMIT command. Displaying the last few links also requires a descending sort on the created_time column, resulting in the following FQL query:
SELECT url,title FROM link WHERE owner = current-user ORDER BY created_time DESC LIMIT number-of-links
Armed with the desired FQL queries, we can move forward to the next step: using the queries in the Facebook Connect application.