views:

2039

answers:

1

How can i get my current UID with FQL.. i want to save traffic and requests with getting the the friends of a user with fql.multiquery

"query1": GET NEED MY USERID "query2":"SELECT uid, first_name, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=MYUSERID) order by first_name"

should return my friends! getting users with friends.get and then users.getInfo needs 2 requests and is not optimal...

Thank you

+2  A: 

Your first query should be entirely unnecessary, as Facebook always provides the uid to an application via the fb_sig_user parameter (POST or GET). I'm not sure what kind of FQL query you could use to get a uid based on some other form of information. There's no sessions table or anything available to FQL (available tables are listed here).

For multi-queries however, I'm fairly certain that this page describes exactly what you need to do, but I'll throw some code together in the way that I would do it.

If it was a PHP app, and I wanted to do this server side, I would create a couple of JSON-formatted strings and send them as a query as follows:

$fql= '{
 "userinfo":"SELECT uid FROM user_standard_info WHERE first_name=\'zombat\'",
 "friends":"SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM #userinfo)}"
}';
$res = $facebook->api_client->fql_multiquery($fql);

print_r($res['userinfo']);
print_r($res['friends']);

This should produce a dump of your query results.

Assuming you have your current uid available from the fb_sig_user parameter (which you should), then your problem should be solved by something like this:

$fql= '{
 "friends":"SELECT uid2 FROM friend WHERE uid1='.$your_uid.',"
 "friendinfo":"SELECT * FROM standard_user_info WHERE uid IN (SELECT uid2 FROM #friends)"
}';
$res = $facebook->api_client->fql_multiquery($fql);

Note: You may want to have a careful look at some of the queries you're trying to do. Many tables, such as friend, can only be used if you're dealing with a logged-in user.

zombat

related questions