Facebook Preload FQL Help

Facebook have a beta feature on their platform api called Preload FQL. It allows you to specify an FQL call to take place before the request for the page is made from your servers. This could save a full round trip of api request if you’re clever about it.

Well the wiki article is quite large but misses a few points I thought it worth noting…

1) You need to escape all forward slashes with a backslash

In the regexp / always needs to be submitted as \/

2) The url they match again is the full callback url you submitted for your app not the canvas url

You aren’t matching just the file names, you can match back down the folders.
So if you use a folder called myapp/ for your index page then your url regexp could be ‘myapp\/$’ for the home page
You could then do ‘myapp\/anotherpage\.php$ for a different file and ‘myapp\/folder\/$ for another folder

3) Whatever keys you use in the submitted array are used as the new $_POST var keys

They take your array key ‘user_app_friends’ below and append ‘fb_sig_’ to it. The final key would be ‘fb_sig_user_app_friends’ in this case

4) You can submit multiple matches in one api request

Although the examples only show:

$fetch = array(
	'user_app_friends' => array(
				'pattern' => 'myapp\/$', 
				'query' => 'SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = {*user*})')
		);
$facebook->api_client->admin_setAppProperties(array('preload_fql' => json_encode($fetch)));

You could submit:

$fetch = array(
	'user_app_friends' => array(
				'pattern' => 'myapp\/$', 
				'query' => 'SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = {*user*})'),
	'user_friends' => array(
				'pattern' => 'myapp\/.+$',
				'query' => 'SELECT uid2 FROM friend WHERE uid1 = {*user*}'
				)
	);
$facebook->api_client->admin_setAppProperties(array('preload_fql' => json_encode($fetch)));

5) The easiest way to get data back from the new $_POST variables in json_decode

Stick the $_POST variable into json_decode(); and then use var_dump to see what you get. It’s usually pretty obvious.

$user_app_friends = json_decode($_POST['fb_sig_user_app_friends']);
var_dump($user_app_friends);

[carousel keywords=”facebook applications” tag=”fetchit-21″]

2 Replies to “Facebook Preload FQL Help”

Comments are closed.